转盘不转动的问题

Stack Overflow is a question and answer site for professional and enthusiast programmers. It‘s 100% free, no registration required.

jQuery Rotate - IE7 & IE8 Issues

up vote

11

down vote

favorite

3

I am using Jquery Rotate to rotate an image around a meter, and it works great but in IE7 and IE8 it gets pushed up about 200 pixels and has a black stroke/border around the image.

I am using jQueryRotate3.js which has it working, but the position is off, and not sure where the black border is coming from?

JS:

var start = 0;

// Sets the Value of the City for now

var angle = 1 + Math.floor(Math.random() * 180);

$("img.pointer").rotate({

angle: start,

animateTo: angle,

easing: $.easing.easeInOutSine

})

HTML:

<div class="city-details">

<div class="details">

<img class="pointer" src="http://demo.omnigon.com/christian_bovine/shamelesscity/images/pointer.png" />

</div>

</div>

You can see the code here: http://jsfiddle.net/xtian/6gcS8/1/

I would really like to get this working in IE7 and IE8.

jquery rotation image-rotation

shareimprove this question

asked Dec 5 ‘12 at 20:31

Xtian

79342865

That looks like the plugin jQueryRotate3.js is doin something funky because if you comment out your JS the position is fine –  Ronnie Dec 7 ‘12 at 22:59

IE9 < has problems with filter and PNGs (it‘s not only IE6), the black border happens because of the alpha channel. You may use a 8bit PNG or a gif, it would work. –  pocesar Dec 7 ‘12 at 23:14

add a comment

3 Answers

activeoldestvotes

up vote

5

down vote

accepted

+100

jsFiddle DEMO

I looked into the jQuery Rotate v3.1 script your using and it‘s sparse with just the minimal it needs to get the job done for IE, which is nice considering.

Just include two CSS rules for top and left, based on your margin-top and margin-left values to have it working in IE series of non CSS3 browsers.

Example:

img.pointer{

display: block;

width: 192px;

height: 11px;

top: 211px;

left: 48px;

margin: 211px 0 0 48px;

}

Note there is no need to set CSS position since this script sets it to absolute which over-rides anything you provide.

A method to fix the image black border issue in IE browsers is to set the background-color property to the value that matches the background... expect in your case you have 3 colors of blue along with white in the middle section... so that‘s not a good idea.

Instead, use the most common solution which is a PNG8 Filetype Image with Transparency, as discussed in this SO Answer.

shareimprove this answer

edited Dec 9 ‘12 at 12:10

answered Dec 9 ‘12 at 11:29

arttronics

8,93521545

Having used a PNG8 with alpha transparency, this approach, which normally solves transparency issues with IE, does not work in ie7/8. There are still black borders after rotation. –  robert.egginton Jun 25 ‘13 at 17:00

add a comment

up vote

0

down vote

I managed to get it working by removing the margin and setting placement with relative positioning like:

img.pointer{

display: block;

width: 192px;

height: 11px;

margin: 211px 0 0 48px;

}

to

img.pointer{

display: block;

width: 192px;

height: 11px;

position: relative;

top: 218px;

left: 50px;

}

I don‘t have ie7/8 installed but I this works with IE9 compatibility view settings, which showed the misplaced needle in the original fiddle (and it still behaves as expected in Chrome & Firefox).

Try this updated fiddle and let me know if you still have issues: http://jsfiddle.net/6gcS8/4/

shareimprove this answer

answered Dec 7 ‘12 at 23:07

WebChemist

2,72021726

add a comment

up vote

0

down vote

Doing stuff like rotation or fading in IE7/8 is always likely to have unwanted side effects because it‘s going beyond the standard capabilities of the browser. In every other browser it‘s dead easy, but for old IE your jQuery plugin is going to be doing some pretty hacky stuff to make it work. That hacky stuff may work in some cases, but tends to be very brittle and easily broken.

IE‘s rotation mechanism is very clunky. The described problem of the image being moved up 200 pixels sounds like the rotation centre point may be incorrect. This is something I‘ve encountered a lot when trying to work with rotation in IE. I would have expected your jQuery plugin to deal with that transparently, but if it‘s getting it wrong then I‘m not sure how you‘d correct it without bypassing the plugin entirely or using a different image for IE that is 200 pixels taller or something like that.

Re the black border, this may possibly be an issue with handling the alpha channel on the PNG image. You may want to confirm this by using a GIF image instead (although it won‘t look as good).

But overall, my main recommendation is to avoid doing this kind of thing in old IE entirely. It‘s just got too many issues to make it worth the effort.

Looking at your jsFiddle example, it seems like you‘re doing this in order to draw and animate a speedometer-type gauge.

May I suggest an alternative approach which does away with the need to mess around with rotating DOM elements entirely.

There is a Javascript library called Raphael, which draws vector graphics. It works in all browsers, including old IE versions. It is very easy to draw a good looking speedo gauge using Raphael. In fact, I provided a 4-line JS script in another answer here on SO to do exactly that. See here: Drawing a half gauge/speedometer (JavaScript Canvas or Java Swing Example needed). You could take that script, modify it to use your existing gauge background image, and bingo, a working speedo gauge in all browsers, without any of the bugs involved in trying to make IE do things is isn‘t designed for.

Hope that helps.

时间: 2024-10-24 01:37:55

转盘不转动的问题的相关文章

旋转转盘选择Menu--第三方开源--CircleMenu

CircleMenu在github上的项目主页是:https://github.com/zhangphil/Android-CircleMenu CircleMenu用法简单,JAVA代码: package com.szugyi.circlemenu; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.TextView; import and

(素材源码)猫猫学iOS(四十六)之网易彩票幸运大转盘

猫猫分享,必须精品 原创文章,欢迎转载.转载请注明:翟乃玉的博客 地址:http://blog.csdn.net/u013357243?viewmode=contents 素材源码地址:http://download.csdn.net/detail/u013357243/8713827 效果 代码: NYWheel NYWheel.h // // NYWheel.h // 网易彩票幸运大转盘 // // Created by apple on 15-5-18. // Copyright (c)

纯CSS3大转盘抽奖(响应式、可配置)

源于前段时候微信小程序最初火爆公测时段,把以前用 Canvas 实现的大转盘抽奖移植成微信小程序,无奈当时小程序对 Canvas 支持不够完善,只好降低用 CSS3 实现.虽然比不上 Canvas 绘图的绚丽,但也总算完成了一个抽奖的 Demo,详见:https://github.com/givebest/wechat-turntalbe-canvas. 事后想起,CSS3 实现也并不是无有益处,比如简单.快捷.调试方便.渲染想来也是要比 Canvas 要高效的,更重要的一点是支持媒体查询,大转

中奖概率算法(php 可用于刮刮卡,大转盘等抽奖算法)

php中奖概率算法,可用于刮刮卡,大转盘等抽奖算法.用法很简单,代码里有详细注释说明,一看就懂 <?php /* * 经典的概率算法, * $proArr是一个预先设置的数组, * 假设数组为:array(100,200,300,400), * 开始是从1,1000 这个概率范围内筛选第一个数是否在他的出现概率范围之内, * 如果不在,则将概率空间,也就是k的值减去刚刚的那个数字的概率空间, * 在本例当中就是减去100,也就是说第二个数是在1,900这个范围内筛选的. * 这样 筛选到最终,总

IOS开发——UI进阶篇(十八)核心动画小例子,转盘(裁剪图片、自定义按钮、旋转)图片折叠、音量震动条、倒影、粒子效果

一.转盘(裁剪图片.自定义按钮.旋转) 1.裁剪图片 将一张大图片裁剪为多张 // CGImageCreateWithImageInRect:用来裁剪图片 // image:需要裁剪的图片 // rect:裁剪图片的尺寸,传递是像素 CGImageRef norImage = CGImageCreateWithImageInRect(norBigImage.CGImage, clipRect); 2.每次点击按钮立马变为选中状态,并且取消上次的按钮的选中状态 当然还要重写- (void)setH

[jQuery编程挑战]002:实现一个转盘大抽奖

body { background-color: #F2F2F2; text-align: center; } .container { position: relative; width: 500px; height: 500px; margin: 0 auto; } .pic { position: absolute; width: 100px; height: 100px; border-radius: 50px; overflow: hidden; transition: width e

大公司移动前端开发面试题——做转盘

"如果有个做转盘的需求,你准备怎么做?设计师只会提供一个转盘的图片,其余都需要你完成,不能用框架和类库." "这个转盘没有惯性的需求,只要求在手机上,用手指拖转盘,能让转盘跟随手指转起来即可." 这是我在面试前端开发人员时,经常会问到的一道题.转盘是类似上图的样子. 博主之前在M公司和C公司的时候,经常用这题面试移动前端开发工程师.M公司的产品和设计是美国团队,在个别项目上UI设计比较大胆脱俗,对前端开发人员有较高的要求.C公司的只会JS的前端开发人员占比较大,产品

php中奖概率算法,可用于刮刮卡,大转盘等抽奖算法

php中奖概率算法,可用于刮刮卡,大转盘等抽奖算法.用法很简单,代码里有详细注释说明,一看就懂 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 <!--?

微信大转盘

1.创建大转盘对象: //添加大转盘对象并添加大转盘奖项对象(一等奖,二等奖,三等奖等等) public ActionResult WheelCreate(WheelViewModel form) { var UserId = WebSecurity.GetUserId(User.Identity.Name); var user = UserProfileRepository.Find(Specification<EasyWeixin.Model.UserProfile>.Eval(o =&g

canvas转盘抽奖的实现(一)

网络上已经有了很多转盘抽奖的代码,但大多是用jQuery插件实现的,其中的原理比较难弄明白,于是自己摸索了一个.最终效果如下: 实现步骤: 1.根据奖品数量绘制转盘 var r1 = 200, //外圆半径 r2 = 160, //奖品文字距离圆心的位置 r3 = 60, //中心按钮半径 centerX = c.width / 2, //中点 centerY = c.height / 2, PI = Math.PI, prizeList = ['一等奖','二等奖','三等奖','四等奖','