使用Blueimg Gallery我想知道如何在单击库中的img class=".slide-content"
时始终显示库控件(.blueimp-gallery-controls
),而不是显示和隐藏它们。
查看blueimp-galley.min.js(我用Online JavaScript美化程序对其进行了美化),我发现了几个点击处理程序,也指示了库控件的切换功能。
toggleControls: function() {
var a = this.options.controlsClass;
this.container.hasClass(a) ? this.container.removeClass(a) : this.container.addClass(a)
},
在我看来,简单地评论这4句话就给了我想要的行为。然而,我真的不喜欢改变原来的剧本。
这样做还会在脚本的这一部分的最后(this.toggleControls()
)抛出一个Uncaught TypeError: undefined is not a function
错误。
f(c.toggleClass) ? (this.preventDefault(b), this.toggleControls()) : f(c.prevClass) ? (this.preventDefault(b), this.prev()) : f(c.nextClass) ? (this.preventDefault(b), this.next()) : f(c.closeClass) ? (this.preventDefault(b), this.close()) : f(c.playPauseClass) ? (this.preventDefault(b), this.toggleSlideshow()) : e === this.slidesContainer[0] ? (this.preventDefault(b), c.closeOnSlideClick ? this.close() : this.toggleControls()) : e.parentNode && e.parentNode === this.slidesContainer[0] && (this.preventDefault(b), this.toggleControls())
从脚本的那一行末尾删除, this.toggleControls()
可以消除这个错误,但我认为所有这些都不是正确的方法。
有没有一种方法可以在用户添加的脚本中覆盖该脚本中的命令,类似于CSS中的!important
规则?像这样,当BlueimpGallery有更新时,我可以保留源代码并上传最新版本。
如果不是问得太多,也许作者Sebastian Tschan可以联系上它?
非常感谢您的帮助:)
将类blueimp-gallery-controls
添加到blueimp-gallery
div使控件从一开始就可见+切换功能仍然有效
<div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls">
希望能有所帮助。
为了显示控件,您必须将blueimp库控件类添加到库容器中。
你的集装箱看起来像这个
<div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls">
<div class="slides"></div>
<h3 class="title"></h3>
<a class="prev">‹</a>
<a class="next">›</a>
<a class="close">×</a>
<a class="play-pause"></a>
<ol class="indicator"></ol>
</div>
然后,您可以通过覆盖默认选项来解除对单击处理程序的绑定。在初始化图库之前,覆盖这些选项非常重要。
<script>
blueimp.Gallery.prototype.options.toggleControlsOnReturn = false;
blueimp.Gallery.prototype.options.toggleControlsOnSlideClick = false;
</script>
我不确定这个主意是好主意还是坏主意。这似乎是最简单、最直接的途径。
.blueimp-gallery > .prev,
.blueimp-gallery > .next,
.blueimp-gallery > .close,
.blueimp-gallery > .title,
.blueimp-gallery > .play-pause {
display: block;
}
我在SASS工作流程中添加了Blueimp CSS,并将控制按钮的显示属性更改为block
。我还没有取消连接切换库控件类的单击处理程序,所以它仍然会触发。
要禁用图像点击,可以将toggleControlsOnSlideClick
设置为假
示例:
<div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls">
<div class="slides"></div>
<h3 class="title"></h3>
<a class="prev">‹</a>
<a class="next">›</a>
<a class="close">×</a>
<a class="play-pause"></a>
<ol class="indicator"></ol>
</div>
<script>
document.getElementById('links').onclick = function (event) {
event = event || window.event;
var target = event.target || event.srcElement,
link = target.src ? target.parentNode : target,
options = {index: link, event: event, toggleControlsOnSlideClick: false},
links = this.getElementsByTagName('a');
blueimp.Gallery(links, options);
};
</script>