這是片段,我需要它們放入一個公共文件。這個想法是有一個extern .js文件與所有這些片段我試圖複製一個文件中的所有代碼,但它不起作用。是否有可能有一個以上的$(document)。就緒(函數?如何在一個文件中收集幾個小的JavaScript片段
<!-- Java Script //-->
<script type="text/javascript">
$(".collapse").collapse()
$('#menu').collapse({
toggle: false
})
</script> <!-- end of navigation -->
<script type="text/javascript">
var jump=function(e)
{
//prevent the "normal" behaviour which would be a "hard" jump
e.preventDefault();
//Get the target
var target = $(this).attr("href");
//perform animated scrolling
$('html,body').animate(
{
//get top-position of target-element and set it as scroll target
scrollTop: $(target).offset().top
//scrolldelay:1 seconds
},1000,function()
{
//attach the hash (#jumptarget) to the pageurl
location.hash = target;
});
}
$(document).ready(function()
{
//$('a[href*=#]').bind("click", jump);
$('a[href*=#]').not(document.getElementsByClassName("carousel-control")).bind("click", jump);
return false;
});
</script> <!-- // end of smooth scrolling -->
<!-- // Shows menu after 50px -->
<script type="text/javascript">
var fixed = false;
$(document).scroll(function() {
if($(this).scrollTop() > 25) {
if(!fixed) {
fixed = true;
$('#navigation').css({position:'fixed', display:'inline'});
}
} else {
if(fixed) {
fixed = false;
$('#navigation').css({position:'relative', display:'block'});
}
}
});
</script>
你能不能被軟件寫我,我怎麼會做呢?在此先感謝。
哦,是的,它可能有一個以上的$(document)。就緒,但也許並不理想。請參閱此問題: http://stackoverflow.com/questions/1327756/can-you-have-multiple-document-readyfunction-sections – Culme