使用氚来移动html元素

Ale*_*one 3 html move moovweb tritium

我正在使用Moovweb SDK制作网站的移动版本,我需要将图像从一个div移动到另一个div.我怎么能用氚做到这一点?

<body>
  <div class="kittens">
    <img src="images/husky.jpg" id="husky">
  </div>

  ...

  <div class="puppies">
    [need to move img here]
  </div>
</body>  
Run Code Online (Sandbox Code Playgroud)

小智 5

有几种方法可以做到这一点.

我觉得最吸引人的方法是使用一些XPath轴和move_here命令:

$("./body/div[contains(@class,'puppies')]") {
  move_here("ancestor::body/div[contains(@class,'kittens')]/img[@id='huskey']")
}
Run Code Online (Sandbox Code Playgroud)

这种方式使用较少的字符获得相同的效果(但速度较慢):

$("//div[contains(@class,'puppies')]") {
  move_here("//img[@id='huskey']")
}
Run Code Online (Sandbox Code Playgroud)

我喜欢这样做的第一种方式是,一般来说,你正在寻找的img不会如此贴近身体.而不是ancestor::body你可以做,//img[@id=''huskey]但这可能会慢得多.使用祖先的另一个好处是它显示了两个元素之间的连接.