简体   繁体   English

在iframe上禁用滚动,直到点击为止?

[英]disable scroll on iframe until clicked on?

I have made a website that shows 3D CS:GO Skins 我创建了一个显示3D CS:GO Skins的网站

i am having a problem with the iframe/design 我遇到了iframe / design的问题

when you scroll up or down the page once you get to the iframe it starts zooming in/out on the model 当您到达iframe时向上或向下滚动页面,它会开始放大/缩小模型

currently the only way i can disable the zooming feature is by stopping it all together by changing the iframe source link from 目前,我可以禁用缩放功能的唯一方法是通过更改iframe源链接来一起停止它

https://sketchfab.com/models/63b30614212c460fbee04d85eabd9c83/embed?autospin=0.2&autostart=1&camera=0&waitresources=1&ui_stop=0&transparent=1&ui_related=0&scrollwheel=1 https://sketchfab.com/models/63b30614212c460fbee04d85eabd9c83/embed?autospin=0.2&autostart=1&camera=0&waitresources=1&ui_stop=0&transparent=1&ui_related=0&scrollwheel=1

to

https://sketchfab.com/models/63b30614212c460fbee04d85eabd9c83/embed?autospin=0.2&autostart=1&camera=0&waitresources=1&ui_stop=0&transparent=1&ui_related=0&scrollwheel=0 https://sketchfab.com/models/63b30614212c460fbee04d85eabd9c83/embed?autospin=0.2&autostart=1&camera=0&waitresources=1&ui_stop=0&transparent=1&ui_related=0&scrollwheel=0

(changing scrollwheel=1 to scrollwheel=0) (更改滚轮= 1到滚轮= 0)

is there any way that i can disable iframe scrolling interaction until the iframe has been clicked on or with a check box/button or something similar that could toggle it? 有没有办法,我可以禁用iframe滚动交互,直到点击iframe或使用复选框/按钮或类似的东西可以切换它?

prefer an answer using jquery/php/html but anything that fixes it will help a ton 喜欢使用jquery / php / html的答案,但任何修复它的东西都会有所帮助

Thanks 谢谢

If your iframe is a fixed size, follow it immediately with a clickable link that fits the size of the iframe, but doesn't contain anything. 如果您的iframe是固定大小,请立即使用符合iframe大小的可点击链接,但不包含任何内容。 Give it a negative top margin, so it moves up over top of the iframe. 给它一个负的上边距,因此它向上移动到iframe的顶部。 Then hide it once it's been clicked upon. 然后在点击后隐藏它。

HTML: HTML:

<a id='clearBox' href='javascript:removeClearBox()'>&nbsp;</a>

Javascript: 使用Javascript:

function removeClearBox() {
    $('#clearBox').addClass('hidden');
}

CSS: CSS:

#clearBox {
    width: [iframe width]px;
    height: [iframe height]px;
    display: block;
    margin-top: -[iframe height]px;
    text-decoration: none;
}

/*in case you don't have a .hidden class:*/
.hidden { display: none; }

You may also need to play with z-index , depending on what's in the iframe, but that's easy enough to figure out. 您可能还需要使用z-index ,具体取决于iframe中的内容,但这很容易理解。

Your stylings may vary, and it may also be possible to use dynamic sizing with more javascript. 您的样式可能会有所不同,也可能使用更多javascript动态调整大小。

For what it's worth here is what I use: 这里的价值是我使用的:

<div class="overlay" onClick="style.pointerEvents='none'"></div>
<iframe src="https://google.com" width="100%" height="330px"></iframe>

and

.overlay {
   background:transparent; 
   position:relative; 
   z-index:1000;
   width:100%;
   height:330px; /* your iframe height */
   top:330px;  /* your iframe height */
   margin-top:-330px;  /* your iframe height */
   cursor:pointer;
}

Try to alter the iframe's src after you track on user's click. 跟踪用户的点击后,尝试更改iframe的src。

eg 例如

$('body').click(function(){
    $('iframe').prop('src', newUrlWithScrollwheel);
});

Also a float element above that iframe is a considerable choice too, as if you click in the iframe, this click function may not work as it is only for parent window. 此iframe上方的浮动元素也是一个相当大的选择,就像您在iframe中单击一样,此单击函数可能无法正常工作,因为它仅适用于父窗口。

You can change the embedded url call on the fly. 您可以动态更改嵌入式网址调用。

    var scroll = 1;
    var url = 'https://sketchfab.com/models/63b30614212c460fbee04d85eabd9c83/embed?autospin=0.2&autostart=1&camera=0&waitresources=1&ui_stop=0&transparent=1&ui_related=0&scrollwheel=';

Then you can change the scroll variable to 0 or 1 under different curcumstances and use jQuery to update the iframe: 然后你可以在不同的情况下将滚动变量更改为0或1,并使用jQuery更新iframe:

    $('#modelviewer').attr('src', url + scroll);

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

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