只是想知道如果有人有任何洞察,爲什麼這可能會發生。 我在我的網站上有一張地圖,當你將鼠標移動到它所在的容器的邊界時,它會滾動。當你將鼠標懸停在它的上方時,它也會突出顯示一個特定的城市,這是通過創建一個具有與原始地圖。因此,我只是應用相同的左和頂CSS來使兩個圖像一致移動。示例在這裏:http://www.bestattorney.com/locations/jquery animate()調用2個元素只適用於一個?
我的問題是,當您將鼠標懸停在地圖下方的鏈接上時,您徘徊的區域應該位於屏幕的中心。它的工作原理,但我想添加一點點的動畫,這樣的舉動是不那麼震撼。當我將動畫({})從0更改爲1000時,結果是隻有疊加圖像會移動,如下所示:http://www.bestattorney.com/locations/locations2.html
我想知道是否有任何理由認爲任何人都可以從其頂部爲什麼會發生這種情況?如果兩個圖像像第一個例子中的do一樣移動,那將會很棒。
我懷疑是有一個setInterval(100)運行animate函數,這意味着在第一個動畫完成時會有10個動畫()運行。我不太確定是否有任何事情要做,希望有人能提供一些見解!謝謝大家!
(滾動插件由Mjfisheruk:https://github.com/mjfisheruk/jquery.pan) 簡化代碼供參考,或者你可以看看源代碼。 如果我能回答任何問題,請讓我知道,謝謝。
var interval; //creates the setInterval object
$("#container").pan({
//Initialize scrolling by placing mouse cursor at the edge of map.
});
var pan = function(areaX,areaY){
var onInterval = function() {
//If the mouse is on the edge of the map
//check which way the mouse is moving
//set varX and varY to the location they should be at
if (areaX != "" & areaY != "") {
varX = areaX;
varY = areaY;
}
$("#container img").animate({
left: varX + "px",
top: varY + "px"
}, 0);
}
interval = setInterval(onInterval,100);
}
$("li").mouseenter(function() {
//find out the coordinates of the hovered area and enter those values in areaX and areaY
clearInterval(interval)
$("#container").pan({
//Initialize scrolling, but this time use hovered area to decide where to scroll to.
},areaX, areaY);
});
<div id="container">
<map>
<area>
<area>
<area>
</map>
<img id="map-overlay">
<img id="background-map">
</div>
<ul>
<li>Location1</li>
<li>Location2</li>
<li>Location3</li>
</ul>
感謝您的幫助!如果我將鼠標懸停在導航鏈接上,並重置它,如果我將鼠標懸停在地圖上,我最終將清除間隔。當我更願意使用stop(true,false)時,我不得不在動畫上調用stop(true,true),以便它不會跳到動畫的結尾,但由於某些原因,仍然會給我帶來同樣的問題我以前有過。我很滿意,但離開它。再次感謝! – mcheah