我正在使用 Moovweb SDK要制作网站的 move 版本,我需要将图像从一个 div move 到另一个。我如何使用氚做到这一点?
<body>
<div class="kittens">
<img src="images/husky.jpg" id="husky">
</div>
...
<div class="puppies">
[need to move img here]
</div>
</body>
最佳答案
有几种方法可以做到这一点。
我觉得最吸引人的方法是使用一些 XPath 轴和 move_here 命令:
$("./body/div[contains(@class,'puppies')]") {
move_here("ancestor::body/div[contains(@class,'kittens')]/img[@id='huskey']")
}
这种方式使用更少的字符获得相同的效果(但速度较慢):
$("//div[contains(@class,'puppies')]") {
move_here("//img[@id='huskey']")
}
我喜欢第一种方式的原因是,一般来说,您要查找的 img 不会离 body 太近。您可以执行 //img[@id=''huskey]
而不是执行 ancestor::body
,但这可能会慢得多。使用 ancestor 的另一个好处是它显示了两个元素之间的联系。
关于html - 使用氚 move html 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16175714/