gpt4 book ai didi

Mouseenter 上的 jQuery 动画问题

转载 作者:行者123 更新时间:2023-12-01 05:03:19 24 4
gpt4 key购买 nike

因此,我在编写网站的这一小部分时遇到了一些困难,但它有一点问题。我只知道 jquery 是危险的,但我希望有人可以帮助我做得更好、更高效。

以下是我认为可以改进的方法,但我不知道如何实现这些:

  1. 翻滚第一个城市后,移动到下一个城市时,不应带回所有其他标记然后重新隐藏它们。它应该隐藏您所在的标记,然后显示您所在的标记目前已结束,但鼠标移开和延迟会带回所有标记。
  2. 目前,如果您以某种方式从一次滚存转到下一次滚滚,节奏很快,动画似乎很拖沓
  3. 这是一个额外的好处,但我最初设想标记会以递增的顺序进行动画处理,而不是同时进行所有动画处理。可以是随机的,也可以是定义的。我认为这将使动画看起来更加流畅。我认为这需要一个循环但就像我之前提到的,我只知道足够的危险。

以下是页面链接:http://204.12.117.109/~sandbox/map/

这是我正在使用的 jquery 代码:

$(function() {
$('.city').mouseenter(function(){

var relid = $(this).attr('rel');

$("#communities div[id!=" + relid + "].pin").animate({
opacity: 0,
top: '-=40',
}, 500);
});
$('.city').mouseleave(function(){

var relid = $(this).attr('rel');

$("#communities div[id!=" + relid + "].pin").animate({
opacity: 1,
top: '+=40',
}, 500, 'easeOutBounce');
});
});

这是我正在使用的 CSS:

#communities { background: url(images/bgCommunities.gif) scroll bottom right no-repeat; position: relative; }
#communities .lists { width: 340px !important; }
#cities li { width: 160px !important; margin: 0px 2px !important; padding: 4px 0 4px 4px; }
#cities li:hover { background-color: rgb(240,240,240); }
#boyle, #long, #santa, #rich, #fres, #sac, #city, #sLA, #coach, #kern, #oak, #merc, #sal, #del { position: absolute; width: 8px; height: 12px; background: url(images/pin.png) 0 0 no-repeat; }
#boyle { top: 230px; right: 95px; }
#long { top: 241px; right: 92px; }
#santa { top: 236px; right: 84px; }
#rich { top: 139px; right: 165px; }
#fres { top: 173px; right: 121px; }
#sac { top: 133px; right: 147px; }
#city { top: 258px; right: 78px; }
#sLA { top: 235px; right: 90px; }
#coach { top: 239px; right: 62px; }
#kern { top: 206px; right: 105px; }
#oak { top: 148px; right: 162px; }
#merc { top: 161px; right: 136px; }
#sal { top: 171px; right: 155px; }
#del { top: 71px; right: 185px; }

这是我正在使用的 HTML:

<div id="communities">
<div class="lists">
<ul id="cities">
<li class="city" rel="boyle"><a href="#">Boyle Heights</a></li>
<li class="city" rel="long"><a href="#">Long Beach</a></li>
<li class="city" rel="santa"><a href="#">Central Santa Ana</a></li>
<li class="city" rel="rich"><a href="#">Richmond</a></li>
<li class="city" rel="fres"><a href="#">Central/SE/SW Fresno</a></li>
<li class="city" rel="sac"><a href="#">Sacramento</a></li>
<li class="city" rel="city"><a href="#">City Heights</a></li>
<li class="city" rel="sLA"><a href="#">South Los Angeles</a></li>
<li class="city" rel="coach"><a href="#" >Coachella Valley</a></li>
<li class="city" rel="kern"><a href="#">South Kern</a></li>
<li class="city" rel="oak"><a href="#">East Oakland</a></li>
<li class="city" rel="merc"><a href="#">SW Merced/East Merced</a></li>
<li class="city" rel="sal"><a href="#">East Salinas (Alisal)</a></li>
<li class="city" rel="del"><a href="#">Del Norte County</a></li>
</ul>
</div>
<div class="pin" id="boyle"></div>
<div class="pin" id="long"></div>
<div class="pin" id="santa"></div>
<div class="pin" id="rich"></div>
<div class="pin" id="fres"></div>
<div class="pin" id="sac"></div>
<div class="pin" id="city"></div>
<div class="pin" id="sLA"></div>
<div class="pin" id="coach"></div>
<div class="pin" id="kern"></div>
<div class="pin" id="oak"></div>
<div class="pin" id="merc"></div>
<div class="pin" id="sal"></div>
<div class="pin" id="del"></div>

最佳答案

明白了(东部时间 02:31)! (现在正在研究随机版本......我喜欢挑战!):

编辑(参见http://zequinha-bsb.int-domains.com/map/cities.html)

知道了 2 @ 3:29am est(我是按小时付费......还是根本不付费?)随机版本位于底部及其各自的链接。

<script type="text/javascript">

var firstEntry = true;
var lastOn = '';

function showAllPins() {
if ($('#communities').hasClass('theMouseIsOff')) {
$("#communities div[id!=''].pin").animate({
opacity: 1,
top: '+=40',
}, 500, 'easeOutBounce');
firstEntry = true;
$('#communities').removeClass('theMouseIsOff');
}
}
function showPin(relid){
lastOn = relid;
if ($('#communities').hasClass('theMouseIsOff')) $('#communities').removeClass('theMouseIsOff');
if (firstEntry == true) {
$("#communities div[id!=" + relid + "].pin").animate({
opacity: 0,
top: '-=40',
}, 500);
firstEntry = false;
} else {
$("#communities div[id=" + relid + "].pin").animate({
opacity: 1,
top: '+=40',
}, 500, 'easeOutBounce');
}
}
function removeLastPin() {
$('#communities').addClass('theMouseIsOff');
$("#communities div[id=" + lastOn + "].pin").animate({
opacity: 0,
top: '-=40',
}, 500);
setTimeout('showAllPins()',5000);
}

$(document).ready( function () {
$('.city').mouseenter( function () {
relid = $(this).attr('rel');
showPin(relid);
}).mouseleave( function () { removeLastPin() });
});

</script>

随机版本:

<script type="text/javascript">

var firstEntry = true;
var lastOn = '';

function showAllPins() {
if ($('#communities').hasClass('theMouseIsOff')) {
var citiesArr = [];
$('.pin').each( function () {
citiesArr.push(this.id);
$('#'+this.id).hide();
});
var stillHidden = citiesArr.length;
while (stillHidden > 0) {
var a = Math.floor(Math.random()*citiesArr.length);
if ($('#'+citiesArr[a]).is(':hidden')) {
$('#'+citiesArr[a]).show().delay(Math.floor(Math.random()*900)).animate({
opacity: 1,
top: '+=40',
}, Math.floor(Math.random()*900), 'easeOutBounce');
stillHidden--;
}
}
firstEntry = true;
$('#communities').removeClass('theMouseIsOff');
}
}
function showPin(relid){
lastOn = relid;
if ($('#communities').hasClass('theMouseIsOff')) $('#communities').removeClass('theMouseIsOff');
if (firstEntry == true) {
$("#communities div[id!=" + relid + "].pin").animate({
opacity: 0,
top: '-=40',
}, 500);
firstEntry = false;
} else {
$("#communities div[id=" + relid + "].pin").animate({
opacity: 1,
top: '+=40',
}, 500, 'easeOutBounce');
}
}
function removeLastPin() {
$('#communities').addClass('theMouseIsOff');
$("#communities div[id=" + lastOn + "].pin").animate({
opacity: 0,
top: '-=40',
}, 500);
setTimeout('showAllPins()',2000);
}

$(document).ready( function () {
$('.city').mouseenter( function () {
relid = $(this).attr('rel');
showPin(relid);
}).mouseleave( function () { removeLastPin() });
});

</script>

编辑(在removeLastPin中删除了relid作为参数)

您可以在这里查看:http://zequinha-bsb.int-domains.com/map/randomCities.html

关于Mouseenter 上的 jQuery 动画问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8146314/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com