我希望在div中对内容进行一些"预览",所以我把它做得很小,只显示了第一行.现在我要设置它的动画,当你点击标题时,div将具有100%的高度,但是当我使用animate(高度:"100%")时,没有很好的滑动.
<a href="javascript:void(0);" class="show_it">title:</a>
<div>
content<br>
content_hidden
</div>
<script>
$('.show_it').click(function() {
$(this).next("div").animate({
height: 'auto'
}, 1000, function() {
});
});
</script>
<style>
div{
height:20px;
overflow:hidden;
}
</style>
Run Code Online (Sandbox Code Playgroud) 为什么最后p没有突出显示?
w3schools说:
为p元素指定背景颜色,该元素是其父元素的最后一个子元素
那么最后p应该突出显示吗?
<style>
div p:last-child {
background: #ff0000;
}
</style>
<div>
<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p>The fourth paragraph.</p>
<span>The first span.</span>
<div>
Run Code Online (Sandbox Code Playgroud)
对你说,用这个 - 这不是我的问题:
div p:last-of-type {...}
Run Code Online (Sandbox Code Playgroud) 我想为背景设置动画,但它不会随着.animate而改变!
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
$(document).ready(function() {
$(".menu").hover(
function() {
$(this).stop().animate({
"background": "-moz-radial-gradient(top, #fff, #cfcfcf)"
}, "slow");
}, function() {
$(this).stop().animate({
"background": "-moz-radial-gradient(top, #fff, #333)"
}, "slow");
});
});?
Run Code Online (Sandbox Code Playgroud) 我想阅读".vm-video-title"-divs中的所有链接,并将它们分别发布在同一个div中.所以我制作了这个剧本:
$('.vm-video-title').each(function(i) {//all divs
$(this).html($(this).html()+$("div.vm-video-title>a").text());//add to div the link
});
Run Code Online (Sandbox Code Playgroud)
但我有问题,它读取所有div的所有链接,并将它们放在一个div中.
例:
<div class="vm-video-title"><a href="...">Text1</a></div>
<div class="vm-video-title"><a href="...">Text2</a></div>
<div class="vm-video-title"><a href="...">Text3</a></div>
Run Code Online (Sandbox Code Playgroud)
输出:
<a href="...">Text1</a>Text1Text2Text3
<a href="...">Text2</a>Text1Text2Text3
<a href="...">Text3</a>Text1Text2Text3
Run Code Online (Sandbox Code Playgroud)
想要输出:
<a href="...">Text1</a>Text1
<a href="...">Text2</a>Text2
<a href="...">Text3</a>Text3
Run Code Online (Sandbox Code Playgroud)