Javascript 如何通过鼠标在文本上添加效果
我需要在鼠标悬停时为文本添加效果 我的js代码:-Javascript 如何通过鼠标在文本上添加效果,javascript,jquery,css,Javascript,Jquery,Css,我需要在鼠标悬停时为文本添加效果 我的js代码:- var j = jQuery.noConflict(); j(document).ready(function() { j('.related_box ul li').hover(function(event) { j(this).stop().animate({ right: "-5px" }, {duration: 'slow',easing: 'easeOutElastic'}); } , function(){ j(this).stop
var j = jQuery.noConflict();
j(document).ready(function() {
j('.related_box ul li').hover(function(event) {
j(this).stop().animate({ right: "-5px" }, {duration: 'slow',easing: 'easeOutElastic'});
}
,
function(){
j(this).stop().animate({ right: "-75px" }, {duration: 'slow',easing: 'easeOutElastic'});
});
});
Html代码:-
<div class="related_box">
<ul class="related_list_ul">
<li class="related_list"><h3><a href="#"></a><span>«</span> About us</h3></li>
<li class="related_list"><h3><a href="#"></a><span>«</span> Call us</h3></li>
<li class="related_list"><h3><a href="#"></a><span>«</span> Contact us</h3></li>
</ul>
</div>
- «联系我们
如何通过鼠标在文本上添加效果。您需要确保要设置动画的元素是
位置:相对代码>或位置:绝对
,否则将向右更改将不会有任何效果。试试这个
j('.related_box > ul > li > a').hover(function(event) {
您可以使用CSS来实现它使用mouseover()
示例:(此处测试)
问题是,代码运行得很好->您是否记得包含jQuery和jQuery UI?当然,您必须添加easings(jQuery UI)并设置初始位置。请添加更多说明。
li.related_list a:hover{ color: #xyz; }
var j = jQuery.noConflict();
j(document).ready(function() {
j("li").mouseover(function(){
j(this).animate({
opacity: 0.25,
left: "+=50",
height: "toggle"
}, 5000, function() {
// Animation complete.
}); // animate
});
});