【发布时间】:2016-07-26 03:58:50
【问题描述】:
所以,我有一个带有图像的 div,当发生特定滚动时,我想将其更改为 gif...
这里是html:
<div class="col-xs-6 mitad" ng-init="varname='images/estandar/impresoraEstandarAnimada.gif'" id="seccion3B">
<img ng-src="{{varname}}" id="gif">
</div>
现在,想法是,更改 varname 中的 url...我尝试了这个但没有用:
if ($(window).width() > 1700 && vistaEstandar.scrollTop > 1596 && vistaEstandar.scrollTop < 2490)
{
lore: 'url(../images/estandar/monitorVeloz1.gif)';
$("#gif").attr("ng-src", "{{lore}}");
}
知道如何让它工作吗?我不太了解 Angular(编程新手),如果我尝试通过仅替换 img 标记中的 SRC 属性来更改它而不使用 Angular,则 gif 将第一次加载,但如果在 if 条件下再次输入或者如果我刷新网站,加载为静态图片
更新:
所有这些 js 代码都已经在控制器中了:
app.controller('estandarCtrl', function ($scope, $rootScope, $routeParams, $location, $http, Data)
{
$(document).ready(function(){
// ----Clases para mantener los colores del header
$(".navbar-header").addClass("fondoHeader");
$("#fondoMenu").addClass("fondoHeader");
$("#footer").removeClass("esconder");
$("#social").removeClass("esconder");
$(".navbar-brand").removeClass("esconder");
$("#botonVideo").removeClass("fondoBoton");
$("#vista").removeClass("barraVista");
// ----Propiedades para los scrollbar
var vistaEstandar = document.getElementById('vista');
vistaEstandar.style.overflow= "auto";
vistaEstandar.style.overflowX= "hidden";
vistaEstandar.style.height = 100 + "%";
$("#vista").smoothWheel();
// ---animaciones para diferentes resoluciones
vistaEstandar.onscroll = function() {animacionesEstandarVista()};
function animacionesEstandarVista()
{
if (($(window).width() > 1700 && vistaEstandar.scrollTop > 1596 && vistaEstandar.scrollTop < 2490) || ($(window).width() > 1700 && document.documentElement.scrollTop > 1596 && document.documentElement.scrollTop < 2490)){
}
else if (($(window).width() > 1700 && vistaEstandar.scrollTop > 3888 && vistaEstandar.scrollTop < 4286) || ($(window).width() > 1700 && document.documentElement.scrollTop > 3888 && document.documentElement.scrollTop < 4286)) {
document.getElementById("section6").style.background = "url(images/estandar/monitorEstandarEntrada.gif)";
document.getElementById("section6").style.backgroundSize = "cover";
document.getElementById("section6").style.backgroundPosition = "bottom";
}
else if (($(window).width() > 1700 && vistaEstandar.scrollTop > 4450) || ($(window).width() > 1700 && document.documentElement.scrollTop > 4450)) {
document.getElementById("section6").style.background = "url(images/estandar/monitorEstandarSalida.gif)";
document.getElementById("section6").style.backgroundSize = "cover";
document.getElementById("section6").style.backgroundPosition = "bottom";
}
else
{
}
});
});
所以我已经有一个部分控制器
【问题讨论】:
-
这段代码写在哪里?
-
你为什么使用 Angular?你不能只改变
img中的src属性吗? -
我不能,因为我解释的原因......当它改变时...... gif 不起作用......它只在第一次打开页面时作为 gif 工作。 ..如果重新加载它将无法工作。现在,gif 只是一个一次性循环 gif
-
@Caro 检查我的答案,看看是否符合您的要求
标签: jquery html angularjs if-statement