简体   繁体   English

为什么选框标签在谷歌浏览器中不起作用。?

[英]why marquee tag not working in google chrome.?

I want to insert an image into marquee tag.我想在选取框标签中插入图像。

I have written following code:我写了以下代码:

<marquee scrollamount="4" behavior="alternate" direction="right" width="300"><img width="180px" style="padding-left:30px;opacity:0.7" src="img/cloud3.png"></marquee>

Its working fine in firefox and IE but not working in chrome.它在 Firefox 和 IE 中工作正常,但在 chrome 中不起作用。 What is the problem.?问题是什么。? Please reply as early as possible.请尽快回复。 Thanks in advance.提前致谢。

Because the marquee tag is a crime against nature.因为marquee标签是对自然的犯罪。 And it's no longer supported in newer versions of Chrome.较新版本的 Chrome 不再支持它。

The marquee is not supported in modern html.现代 html 不支持marquee Chrome dropped support for it a while ago. Chrome 不久前放弃了对它的支持。 You need to implement this via CSS3 or Javascript.您需要通过 CSS3 或 Javascript 来实现。

Further W3C states that it is non standard and should not be used. W3C 进一步声明它是非标准的,不应使用。

The effect can be easily acheived via jQuery or via CSS3效果可以通过jQueryCSS3轻松实现

The marquee element has varying implementations, partly because there has been no published specification for it. marquee元素有不同的实现,部分原因是还没有发布它的规范。 In HTML5, the element is being defined exactly, and HTML5 drafts require support to marquee as defined there .在 HTML5 中,元素被精确定义,并且 HTML5 草稿需要支持其中 定义的marquee (The drafts also declare it “obsolete” and “nonconforming”, but these are just what they say to authors ; the requirements on implementations are different.) However, there are still limitations and differences in support, see eg MDN on marquee . (草案还声明它“过时”和“不符合”,但这只是他们对作者说的;对实现的要求不同。)但是,仍然存在支持方面的限制和差异,例如参见MDN on marquee

In this case, it does not seem to be the image but the attribute behavior="alternate" that causes the problem.在这种情况下,似乎不是图像而是导致问题的属性behavior="alternate" If you remove it, the image will move on Chrome, too.如果您将其删除,该图像也会在 Chrome 上移动。

This is apparently implementation bug rather than lack of support.这显然是实现错误而不是缺乏支持。 Inspecting the DOM in Chrome shows that the behavior property has the value alternate as specified, but it just does not work.在 Chrome 中检查 DOM 显示behavior属性具有指定的值alternate ,但它只是不起作用。 If you add a border to the marquee element in CSS, the image starts moving, alternatingly, but just a few pixels right and left.如果在 CSS 中为marquee元素添加边框,图像将开始交替移动,但只是左右移动几个像素。

If you really alternating direction, it is probably best to use some other technique instead of marquee .如果您真的要交替方向,最好使用其他一些技术而不是marquee For example, a simple moving image can be implemented using JavaScript so that the position is changed in a loop, using a timer, and then you can easily implement alternating direction, too.例如,可以使用 JavaScript 实现简单的运动图像,使用定时器循环更改位置,然后您也可以轻松实现交替方向。 Alternatively, possibly simpler but not as robustly (due to limited browser support), you can use CSS3 animations.或者,可能更简单但不那么健壮(由于浏览器支持有限),您可以使用 CSS3 动画。

HTML: HTML:

<div id="cloud">image</div>

CSS: CSS:

    #cloud{
        width:180px;
        padding-left:30px;
        opacity:0.7;
        animation:slide 10s infinite;
        -moz-animation:slide 10s infinite;//Firefox
        -webkit-animation:slide 10s infinite;//chrome and safari
        -o-animation: slide 10s infinite;//Opera   
}

@keyframes slide{
    0%   {-transform: translate(0px, 0px); }
        100% {-transform: translate(500px,0px); }
}    

@-moz-keyframes spin{
    0%   {-moz-transform: translate(0px, 0px); }
    100% {-moz-transform: translate(500px, 0px); }
}

@-webkit-keyframes slide{
         0%   {-webkit-transform: translate(0px, 0px); }
        100% {    -webkit-transform: translate(500px,0px); }
    }

@-o-keyframes slide{
    0%   {-o-transform: translate(0px, 0px); }
    100% {-o-transform: translate(500px, 0px); }
}

Here is the fiddle:这是小提琴:

http://jsfiddle.net/qCahH http://jsfiddle.net/qCahH

Replace the text with the image.用图像替换文本。

Marquee 已被弃用,因此将在不同浏览器上显示未指定的行为。

Who said it doesn't ?谁说没有?
On Chromium 83.0.4103.61 (Official Build) Built on Ubuntu , running on Ubuntu 18.04 (64-bit) it works flawlessly.在 Chromium 83.0.4103.61(官方版本)上构建在 Ubuntu 上,在 Ubuntu 18.04(64 位)上运行它完美无缺。

Didn't test on Chrome, though.不过没有在 Chrome 上测试。

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

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