我正在使用自定義滾動div
jQuery插件。我希望div
根據瀏覽器窗口大小填充其父級寬度的100%以更改大小。如何將jQuery中的寬度參數作爲像素整數更改爲百分比?
該腳本獲取給定的width
參數,並在整個腳本中使用該參數。腳本的自定義參數似乎只允許我指定像素width
,作爲一個整數:
$.fn.hoverscroll.params = {
vertical: false, // Display the list vertically or not
width: 1280, // Width of the list
height: 230, // Height of the list
arrows: true, // Display arrows to the left and top or the top and bottom
arrowsOpacity: 0.4, // Maximum opacity of the arrows if fixedArrows
fixedArrows: false, // Fix the displayed arrows to the side of the list
rtl: false, // Set display mode to "Right to Left"
debug: false // Display some debugging information in firebug console
};
我想引用百分比,'100%'
,但沒有奏效。有沒有在這裏使用百分比的方法?
如果沒有,有沒有辦法使用下面的腳本,它決定了窗口的寬度,使腳本輸出的像素寬度,並使用該整數作爲jQuery腳本中的參數width
?
<script type="text/javascript">
function alertSize() {
var myWidth = 0;
if(typeof(window.innerWidth) == 'number') {
//Non-IE
myWidth = window.innerWidth;
} else if(document.documentElement && (document.documentElement.clientWidth)) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
} else if(document.body && (document.body.clientWidth)) {
//IE 4 compatible
myWidth = document.body.clientWidth;
}
//window.alert(myWidth);
}
</script>
以供參考,在這裏是插件的完整劇本,我使用: http://rascarlito.free.fr/hoverscroll/js/hoverscroll/jquery.hoverscroll.js