我甚至可能没有正确使用“事件”这个词。这是我想要做的:
我有一个以“阅读更多”开头的链接。当用户将鼠标悬停在"Ream More“链接上并单击它时,我希望右侧的填充稍微扩展一点,然后在悬停停止时收缩。我可以用下面的代码很容易地做到这一点:
$('#post-text a.more-link').hover(
function(){$(this).animate({paddingRight: '18px'}, 200);},
function(){$(this).animate({paddingRight: '4px'}, 200);});但我也想附加文本",请“,当你悬停在它上面的时候。我可以使用.append()做到这一点,但我遇到了一些问题。如果我将它添加到代码中,如下所示:
$('#post-text a.more-link').hover(
function(){$(this).animate({paddingRight: '18px'}, 200), $(this).append(", Please");},
function(){$(this).animate({paddingRight: '4px'}, 200);});然后,每当有人悬停它时,它会添加另一个",请“。我只想添加一次,如果可能的话,在第一次悬停时添加。
此外,我希望“请”留在那里,不要在他们停止悬停时离开。我猜我将需要使用.one()或.bind(),但我不确定它应该用在哪里。
任何帮助都将不胜感激。提前谢谢。
更新:我取得了一些进展,如下所示:
首先,我刚刚学会了如何最终使用.one(),我还学会了.hover()与mouseenter的工作方式相同。所以这就是我现在用的方法:
$('#post-text a.more-link').one('mouseenter', function() {
$(this).append(", Please");});所以我对此很满意,我只需要弄清楚如何添加它和填充动画来获得更多的光晕。
发布于 2011-07-29 01:43:09
use $(this).append(' <span class="whatever">Please</span>');});
and on mouseout $(this).remove('.whatever');而应该使用:
$(document).ready(function(){
$("#sall").live("mouseover mouseout", function(event) {
if ( event.type == "mouseover" ) {
$(this).append('Please');
} else {
var g = $(this).html();
$(this).html(g.substr(0,g.length-"Please".length)); //get rid of please
}
});
})请参阅此示例http://jsfiddle.net/jECW5/
https://stackoverflow.com/questions/6862995
复制相似问题