[英]inserting a javascript variable into a javascript function
我希望有人可以提供幫助,因為我目前很沮喪。 我正在使用speedo popup顯示彈出窗口,但我希望它始終顯示在屏幕的右下角。 我發現(感謝比我聰明的人)代碼來識別某人瀏覽器的像素,並且我已經計算出,為了使彈出窗口正確顯示並計算出變量,我需要減去多少像素,但是現在我需要將該變量寫入speedo彈出功能,以便在正確的位置彈出。
我需要在下面的函數語句中,將“ h”和“ w”變量的值放在“ top:”和“ left:”部分的右側。
我希望這是有道理的。 任何幫助表示贊賞。 謝謝
該代碼包括在下面:
<script type="text/javascript">
// JavaScript
function jsUpdateSize(){
// Get the dimensions of the viewport
var width = window.innerWidth ||
document.documentElement.clientWidth ||
document.body.clientWidth;
var height = window.innerHeight ||
document.documentElement.clientHeight ||
document.body.clientHeight;
document.getElementById('jsWidth').innerHTML = width;
document.getElementById('jsHeight').innerHTML = height;
var w;
var h;
w=width-580;
h=height-270;
document.getElementById('w1').innerHTML = w;
document.getElementById('h1').innerHTML = h;
};
window.onload = jsUpdateSize; // When the page first loads
window.onresize = jsUpdateSize; // When the browser changes size
$(function () {
$.fn.speedoPopup({
//htmlContent: "",
theme: "metro",
width:500,
height:200,
href: "http://delanceyplace.com/subscribe_iframe.php",
autoShow: 1000,
//left:956,
//top:492
responsive: true,
effectIn: 'slideBottom',
effectOut:'slideBottom',
});
});
</script>
所以我想出了一個解決方案,但似乎還差一點-通過使用$(input ...),它只能找到寬度,但是當我在頂部使用代碼時,彈出窗口不會運行。 只需輸入寬度,它就可以運行並正確響應-一如既往,感謝您的幫助。 非常感謝大家。 這是新代碼:
// JavaScript
function jsUpdateSize(){
// Get the dimensions of the viewport
var width = window.innerWidth ||
document.documentElement.clientWidth ||
document.body.clientWidth;
var height = window.innerHeight ||
document.documentElement.clientHeight ||
document.body.clientHeight;
document.getElementById('jsWidth').innerHTML = width;
document.getElementById('jsHeight').innerHTML = height;
var w;
var h;
//var th;
//var lw;
w=width-500;
h=height-200;
document.getElementById('w1').innerHTML = w;
document.getElementById('h1').innerHTML = h;
$(function ()
{
$.fn.speedoPopup({
//htmlContent: "",
theme: "metro",
width:500,
height:200,
href: "http://delanceyplace.com/subscribe_iframe.php",
///autoShow: 60000 // 60 Seconds
autoShow: 1000,
left: $("input[name='w']"),
//top: $("input[name='h']"),
responsive: true,
effectIn: 'slideBottom',
effectOut:'slideBottom'
});
});
};
window.onload = jsUpdateSize; // When the page first loads
// window.onresize = jsUpdateSize; //當瀏覽器更改大小時
您能指定右/下而不是左/上嗎?
$.fn.speedoPopup({
//htmlContent: "",
theme: "metro",
width:500,
height:200,
href: "http://delanceyplace.com/subscribe_iframe.php",
autoShow: 1000,
//left:956,
//top:492
bottom: 0,
right: 0,
responsive: true,
effectIn: 'slideBottom',
effectOut:'slideBottom',
});
});
$ .fn.speedoPopup({...}); 只會被調用一次。 因此,在“調整大小”事件之后,您將必須刪除當前的(或更新其位置)。
我會從您的更新函數中調用jQuery插件。
這是一個精簡的示例,該示例使用Function.bind(...)將寬度和高度附加為“ this”對象。
function update() {
var w = window.innerWidth;
var h = window.innerHeight;
$(function() {
$("#o").text(this.width + " / " + this.height);
}.bind({width: w, height: h}));
}
window.onload = update;
window.onresize = update;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.