我試圖延遲CSS功能。這是我的網站: http://smartpeopletalkfast.co.uk/ppr6/press延遲CSS功能不起作用
當您將鼠標懸停在左上方的圖像上時,它會展開以覆蓋下方的圖像。香港專業教育學院使用下面的代碼(它在頁頭),以改變它的z索引因此,這是擴大圖像總是可見於任何其他:
$("document").ready(function() {
$(".pressimage img").mouseenter(function() {
$(this).css('z-index','100');
});
$(".pressimage img").mouseleave(function() {
$(this).css('z-index','1');
});
});
此代碼的工作,但只要你鼠標關閉它的z-index變化的圖像,所以它不會保持可見,而其大小調整回縮略圖。我需要的是z-index在動畫完成後返回到1,或者z-index更改爲延遲約1/2秒。我想第二個解決方案會更簡單。
我嘗試使用以下,它只設置Z-指數爲100,但從來沒有把它回到1
$("document").ready(function() {
var timer;
$(".pressimage img").mouseenter(function() {
$(this).css('z-index','100');
clearTimeout(timer);
});
$(".pressimage img").mouseleave(1000,function() {
timer = setTimeout(function(){
$(this).css('z-index','1');
}, 500);
});
});
感謝
更新。我在這裏張貼這個,因爲你不能在評論中看到代碼。這是我的實際代碼與您的建議。 jq用於避免jquery版本衝突,它對我網站上的其他js正常工作。
$jq("document").ready(function() {
$jq(".pressimage img").mouseenter(function() {
$jq(this).stop().animate({
width: 260
});
});
$jq(".pressimage img").mouseleave(function() {
$jq(this).stop().animate({
width: 130
});
});
});
$jq("document").ready(function() {
var timer;
$jq(".pressimage img").mouseenter(function() {
$jq(this).css('z-index','100');
clearTimeout(timer);
});
$jq(".pressimage img").mouseleave(1000,function() {
var that = $jq(this);
timer = setTimeout(function(){
that.css('z-index','1');
}, 500);
});
});
代碼現在工作的大部分,但有時確實留下影像與100 感謝
是的,它是一個重複@Loktar。我開了一個新的問題,因爲我取得了一些進展,我認爲我可以更好地描述它。 – Evans
很希望這對你有用:) – Loktar
我更新了我的問題,並且我在鏈接上使用了你的解決方案,所以你可以看到我的意思。謝謝 – Evans