Javascript 未定义变量:脚本中的窗口?
我有一个错误: PHP通知–yii\base\ErrorException 未定义变量:窗口 函数在ewport($el){ 我的部分代码:Javascript 未定义变量:脚本中的窗口?,javascript,php,yii,Javascript,Php,Yii,我有一个错误: PHP通知–yii\base\ErrorException 未定义变量:窗口 函数在ewport($el){ 我的部分代码: <?php $lazyload = <<< JS $(function() { var $window = $(window), images = [], imagesToBeLoaded = 0, i, src; function throttle(func, wait)
<?php
$lazyload = <<< JS
$(function() {
var $window = $(window),
images = [],
imagesToBeLoaded = 0,
i,
src;
function throttle(func, wait) {
var timeout;
return function() {
var context = this, args = arguments;
if(!timeout) {
timeout = setTimeout(function() {
timeout = null;
}, wait);
func.apply(context, args);
}
};
}
function inViewport($el) {
var top = $window.scrollTop(),
left = $window.scrollLeft(),
bottom = top + $window.height(),
right = left + $window.width(),
offset = $el.offset(),
thisTop = offset.top,
thisLeft = offset.left,
thisBottom = thisTop + $el.outerHeight(),
thisRight = thisLeft + $el.outerWidth();
...
JS;
$this->registerJs($lazyload, View::POS_READY);
?>
引用herdoc的名称,以防止PHP将$window
解释为变量:
<?php
$lazyload = <<< 'JS'
...
JS;
引用herdoc的名称,以防止PHP将$window
解释为变量:
<?php
$lazyload = <<< 'JS'
...
JS;