2015-06-28 92 views
-1

我有這個基本的功能,應該在頁面加載時運行,但它似乎沒有被調用,我知道這個函數是正確的,因爲它使用$('window').resize(document).ready(function()is not running the function

的功能是和在頁的端部正在被呼叫時完美地運行,隨後僅由$(window).resize版本的功能和</body>的;

<script> 
    $(document).ready(function() { 
     var sliderImgH = $(".sliderimages").height(); 
     $(".buttonmove:nth-child(1)").css("margin-top", sliderImgH-75); 
    }); 
</script> 
+0

'$(「。sliderimages」)'返回一個集合或單個元素嗎?什麼'$(「。sliderimages」)。height();'return? – guest271314

+0

@ guest271314它爲我的滑塊中的多個元素,它返回圖像的高度 –

+0

如果它返回多個元素,不應該使用'each()'然後? – Machavity

回答

2

嘗試選擇使用第一.sliderimages元件:first

$(document).ready(function() { 
    var sliderImgH = $(".sliderimages:first").height(); 
    $(".buttonmove:nth-child(1)").css("margin-top", sliderImgH-75); 
}); 
+0

仍然不起作用,這裏是鏈接到網站,我只是想移動滑塊按鈕,所以它是在滑塊圖像,http://optential.co.nf/ –

+0

@MattHammond可以描述_「仍然無法工作」_? ,請在Question?鏈接中包含'html',創建stacksnippets,http://jsfiddle.net來演示? – guest271314

+0

這似乎在這裏工作有多奇怪 - https://jsfiddle.net/aL1jk855/ –

相關問題