简体   繁体   English

Javascript 模态 window 代码重新配置为在页面加载时加载,而不是 onclick。 帮助:)

[英]Javascript modal window code reconfigured to load on page load rather than onclick. Help :)

I have a js modal window which opens with an onclick function in a page on my site:我有一个 js 模态 window 以 onclick function 打开我网站上的一个页面:

<a class="highslide" onclick="return hs.expand(this, { slideshowGroup: 'groupC0', wrapperClassName: 'wide-border', outlineType : 'rounded-white', dimmingOpacity: 0.8, align : 'center', transitions : ['expand', 'crossfade'], fadeInOut: true });" href="/images/phocagallery/thumbs/phoca_thumb_l_jen raymond_067 copy.jpg" title="jen raymond_067 copy">
<img alt="jen raymond_067 copy" src="/images/phocagallery/thumbs/phoca_thumb_m_jen raymond_067 copy.jpg">
</a>

I need this triggered as the page loads (not onclick, as above).我需要在页面加载时触发这个(不是 onclick,如上所述)。 I've been playing around with this js我一直在玩这个js

<script type="text/javascript">
$(document).ready(function() {
window.location.href = "/images/phocagallery/thumbs/phoca_thumb_l_jen raymond_067 copy.jpg";
});
</script>

But of course it only loads the image (href) - can you help include the class, title and onclick attributes to this js function - or is there a better way?但当然它只加载图像(href) - 你能帮助包括 class、title 和 onclick 属性到这个 js function - 还是有更好的方法?

Please show me the light:)请给我看灯:)

You can try the following (keeping in mind I have no idea what this function does):您可以尝试以下方法(请记住,我不知道这个 function 做了什么):

 $(document).ready(function(){

    hs.expand($('.highslide'), { 
         slideshowGroup: 'groupC0', 
         wrapperClassName: 'wide-border', 
         outlineType : 'rounded-white', 
         dimmingOpacity: 0.8, 
         align : 'center', 
         transitions : ['expand', 'crossfade'], fadeInOut: true });
    });

Thats the best I can come up with without looking up the hs(highlide?) api.这是我在不查找 hs(highlide?)api 的情况下能想到的最好的。

Try this:尝试这个:

$(function() {
    var yourAElement = $('.highslide')[0];
    hs.expand(yourAElement, { slideshowGroup: 'groupC0', wrapperClassName: 'wide-border', outlineType : 'rounded-white', dimmingOpacity: 0.8, align : 'center', transitions : ['expand', 'crossfade'], fadeInOut: true });
});

Thanks for the solutions above, maybe I'm just not knowledgable with JS, but I couldn't see my way using either, however I did get what I wanted using this method:感谢上面的解决方案,也许我只是不了解 JS,但我看不到我的使用方式,但是我确实使用这种方法得到了我想要的东西:

1) Add an ID to the Anchor tag 1)在Anchor标签中添加一个ID

<a id="autoClick" class="highslide" onClick="return hs.expand(this, { slideshowGroup: 'groupC0', wrapperClassName: 'wide-border', outlineType : 'rounded-white', dimmingOpacity: 0.8, align : 'center', transitions : ['expand', 'crossfade'], fadeInOut: true });" href="/images/phocagallery/thumbs/phoca_thumb_l_jen raymond_067 copy.jpg" title="jen raymond_067 copy">
    <img alt="jen raymond_067 copy" src="/images/phocagallery/thumbs/phoca_thumb_m_jen raymond_067 copy.jpg">
</a>

2) Load JQuery if not already present 2) 如果 JQuery 尚不存在,则加载

3) Add this function 3) 添加这个 function

$(document).ready(function() {
    $('#autoClick').click();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM