婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > Cross-Browser Variable Opacity with PNG

Cross-Browser Variable Opacity with PNG

熱門標簽:蘇州通信外呼系統多少錢 荒野大鏢客2地圖標注怎么變中文 移動400辦理電話 山西旅游景地圖標注 上古卷軸5地圖標注mod 武漢人工外呼系統 中國地圖標注各省份 沈陽智能外呼系統排名 北川縣地圖標注

Periodically, someone tells me about the magic of PNG, how it's the ideal image format for the web, and that someday we'll all be using it on our sites instead of GIF. People have been saying this for years, and by now most of us have stopped listening. Sadly, flaky browser support has made PNG impractical for almost everything; but now, with a few simple workarounds, we can finally put one of its most compelling features to use.

PNG? What?

The Portable Network Graphics, or PNG (pronounced “ping”), image format has been around since 1995, having cropped up during the now long-forgotten GIF scare, when Compuserve and Unisys announced they would begin charging royalties for the use of the GIF image format.

To provide GIF support in their applications, software makers like Adobe and Macromedia must pay royalty fees – fees which are passed down to the end user in the selling cost of the software.

When PNG appeared on the scene, web designers were ready to make the switch to the free, superior format and shun GIF forever. But over time, browsers continually failed to support PNG, and eventually most people started to forget about it. Today, nearly everyone still uses GIF habitually.

Which is a shame, because PNG makes GIF look pretty pathetic: it supports gamma correction, (sometimes) smaller file sizes, loss-less compression, up to 48-bit color, and, best of all, true alpha transparency.

To get why alpha transparency is a big deal, we must first understand one of the most annoying limitations of GIF.

Binary Transparency: the Scourge of GIF

When it comes to transparency, GIF doesn't cut it. Whereas PNG supports alpha transparency, GIF only supports binary transparency, which is a big limitation and has a couple of important implications.

For one, a GIF image can either use no transparent colors at all or have one color that's completely transparent – there are no degrees of transparency.

And if a complex GIF does contain a transparent color, the background color of the web page must match the transparent color, or else the anti-aliased area around the transparent color will be surrounded by ugly haloing and fringing. If you've spent more than five minutes as a web designer, you know what I'm talking about.

The result is that any anti-aliased transparent GIF is inextricably tied to the background color of the web page on which it lives. If you ever decide to change that color, you must also change the GIF.

Miraculously, PNG doesn't behave that way. A PNG can be transparent in varying degrees – in other words, it can be of variable opacity. And a transparent PNG is background-independent: it can live on any background color or image. Say you want your navigation on monkeys-run-amuck.com to be 65% opaque so you can see through it to your orangutan background image. You can do that. A transparent anti-aliased “Gorillas, Chimps, Gibbons, et al” title that can sit on top of any background color or image? You can do that, too.

So What About Browser Support?

By now, of course, we'd all be up to our ears in PNGs if browsers supported them reliably. But seven years after the format's inception, you still can't slap a PNG onto a web page like you can a GIF or JPG. It's disgraceful, but not as bad as it sounds.

It turns out that most of the latest versions of the major browsers fully support alpha transparency with PNG – namely, Netscape 6, Opera 6, and recently-released Mozilla 1, all on Windows; and, for the Mac, Internet Explorer 5, Netscape 6, Opera 5, Mozilla 1, OmniWeb 3.1, and ICab 1.9. Incredibly, PNG even works on Opera 6 for Linux, on WebTV, and on Sega Dreamcast.

Now, what's missing from that list?

IE5.5+/Win, bless its heart, will, in fact, display a PNG, but it doesn't natively support alpha transparency. In IE5.5+/Win, the transparent area of your PNG will display at 100% opacity – that is, it won't be transparent at all.

Bugger. So what do we do now?

Proprietary Code-o-Rama: the AlphaImageLoader Filter

IE4+/Win supports a variety of non-standard, largely ridiculous visual filters that you can apply to any image's style. You can, for instance, fade in an image with a gradient wipe, or make it stretch from nothing to full size, or even make it swipe into place circularly, like a scene change in Star Wars.

A non-pointless gem among these is the AlphaImageLoader filter, which is supported in IE5.5+/Win. When used to display a PNG, it allows for full alpha transparency support. All you have to do is this:

DIV ID="myDiv" 
	STYLE="position:relative; 
	height:250px; 
	width:250px;
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader»
(src='myimage.png',sizingMethod='scale');">/DIV>

(Line wraps are marked ». –Ed.)

And you're in business. Perfect alpha transparency. This code works great, with only the small drawback that it's not part of any accepted web standard, and no other browser on the planet understands it.

Serving up PNGs with JavaScript

So the trick is to determine the user's browser and serve up the images appropriately: if IE5.5+/Win, then we use AlphaImageLoader; if a browser with native PNG support, then we display PNGs the normal way; if anything else, then we display alternate GIFs, because we can't be sure that a PNG will display correctly or at all.

Using a slightly tweaked version of Chris Nott's Browser Detect Lite, we set some global variables to this effect that we can use later on.

// if IE5.5+ on Win32, then display PNGs with AlphaImageLoader
if ((browser.isIE55 || browser.isIE6up)  browser.isWin32) {
	var pngAlpha = true;
// else, if the browser can display PNGs normally, then do that
} else if ((browser.isGecko) |»
| (browser.isIE5up  browser.isMac) |»
| (browser.isOpera  browser.isWin »
	 browser.versionMajor >= 6) |»
| (browser.isOpera  browser.isUnix »
 browser.versionMajor >= 6) |»
| (browser.isOpera  browser.isMac »
	 browser.versionMajor >= 5) |»
| (browser.isOmniweb  »
	browser.versionMinor >= 3.1) |»
| (browser.isIcab  »
	browser.versionMinor >= 1.9) |»
| (browser.isWebtv) |»
| (browser.isDreamcast)) {
	var pngNormal = true;
}

(Note for the faint of heart: complete source code for all the examples we cover is available at the end of the article.)

Tactic 1: Quick and Dirty with document.writes

The simplest, most reliable way to spit out PNGs is using inline document.writes based on the above detection. So we use a function like this:

function od_displayImage(strId, strPath, intWidth, »
	intHeight, strClass, strAlt) {	
 if (pngAlpha) {
 document.write('div style="height:'+intHeight+'px;»
		width:'+intWidth+'px;»
 filter:progid:DXImageTransform.Microsoft.AlphaImageLoader»
 (src=\''+strPath+'.png', sizingMethod=\'scale')" »
	id="'+strId+'" class="'+strClass+'">/div>');
	} else if (pngNormal) {
 document.write('img src="'+strPath+'.png" »
	width="'+intWidth+'"»
 height="'+intHeight+'" name="'+strId+'" »
	border="0" class="'+strClass+'" alt="'+strAlt+'" />');
	} else {
 document.write('img src="'+strPath+'.gif" »
	width="'+intWidth+'"»
 height="'+intHeight+'" name="'+strId+'" »
	border="0" class="'+strClass+'" alt="'+strAlt+'" />');
	}
}

Now we can call the od_displayImage function from anywhere on the page. Any JavaScript-capable browser will display an image, and, if we want to be really careful, we can accompany each call with a noscript> tag that contains a regular img> reference. So the respectable browsers get PNGs normally, IE5.5+/Win gets them with the filter, and all other browsers get regular GIFs, whether they have JavaScript turned on or not.

It's a time-tested method, but what if we want more control over our PNGs?

Tactic 2: the Beauty Majesty of Objects

When I told the programmer in the office next door that I was writing this article, he took one look at my code, glowered at me, and said, “Fool. Where's the abstraction? You need to use objects.”

So now we have a JavaScript object to display PNGs. Here's how we use it:

html>head>
script language="javascript" 
 src="browserdetect_lite.js" 
 type="text/javascript">
/script>
script language="javascript" 
src="opacity.js" 
type="text/javascript">/script>
script type="text/javascript">
var objMyImg = null;
function init() {
	objMyImg = new OpacityObject('myimg','/images/myimage');
	objMyImg.setBackground();
}
/script>

style type="text/css">

#myimg { 
 background: url('back.png') 
 repeat; position:absolute; 
 left: 10px; top: 10px; 
 width: 200px; 
 height: 200px;
 }

/style>

/head>


body onload="init()" background="back.jpg">

div id="myimg">/div>
/body>
/html>

That's it. The cool thing about the OpacityObject is that we just pass it a DIV ID and an image path and we're done. Using the appropriate technique, it applies the image as a background of the DIV, and from there we can do whatever we want with it. Fill it with text, move it across the screen, resize it dynamically, whatever – just like any other DIV.

The object works in any CSS 1-capable browser that can dynamically apply a background image to a DIV with JavaScript. It's completely flexible, and we could even use it in place of the above function.

The trade-off is that it doesn't degrade as nicely. Netscape 4.7/Win/Mac and Opera 5/Mac, for instance, won't display an image at all. And it has another significant problem, which is this:

IE5/Mac only supports alpha transparency when the PNG resides in an img> tag, not when it's set as the background property of a DIV. So PNGs displayed with the OpacityObject will appear 100% opaque in IE5/Mac. This problem is especially frustrating because IE5/Mac is the only browser which natively supports PNG and behaves this way. We've notified Microsoft about this apparent bug and hope for it to be fixed in an upcoming release.

But for now, these issues are the trade-off for flexibility. Obviously, choose the right tactic based on the particular needs of your project. Between them both, you can do pretty much anything with PNGs – like, for instance...

Example 1: Translucent Image on a Photo

In this simple example, we see how the same 80% opaque PNG can be displayed on any kind of background: Translucent Image on a Photo.

Example 2: Anti-Aliased Translucent Navigation with Rollovers

What a beautiful thing it would be, I'm sure you've thought from time to time, to create translucent anti-aliased images that work on any background. Well, check it out: Anti-Aliased Translucent Navigation with Rollovers.

Mouse over the images, observe the behavior of the rollovers, and click “change background” to see how the images behave on different backgrounds. Then view the source. There are a few things worth noting here:

  • To preload the correct images, we create a variable called strExt, which contains either “.png” or “.gif.” As long as our PNGs and alternate GIFs use the same names except for the file extension, the browser will only preload the images that it's actually going to use.
  • We create a class called pngLink and set the cursor property to “pointer.” We pass that class name to the function when we call it, and the function applies the class to the PNG. The result is that the user's pointer turns into a cursor when he rolls over the image links, even though, in IE5.5+/Win, they're really just DIVs. (You might also want to add "display:block" or "display:inline" to your PNG class, depending on how you're using the images, to make them display correctly in Netscape 6. (For details, see Better Living Through XHTML.)
  • We also use a couple of rollover functions specifically for displaying PNGs. It turns out that, while it's possible to dynamically swap out PNGs using the AlphaImageLoader, IE5.5+/Win has a tough time of it; it's damn slow, too slow for effective rollovers. What works better is to apply a background color to the DIV that contains the PNG – the color will shine through the transparent part of the image, and do it fast, too. When we call the function, we send along the name of the image to be displayed and an HTML color – IE5.5+/Win will display the color, and the others will display the image.
  • Notice how those images even have drop shadows. You could stick any background image or color behind them and they would still look great, even if the PNGs were completely transparent. Is that cool or what?

Example 3: Floating Translucent DIV with HTML Text Inside

In the first two examples, we used the quick-and-dirty function from tactic one. Now, we want our PNG to interact with other code on the page, so this time we display it with the OpacityObject.

But remember – there are drawbacks to this approach (see above), the most heartbreaking of which is that this example doesn't work perfectly on IE5/Mac. If that causes you pain, then there's always the quick and dirty function. Otherwise, read on.

First we create a DIV, give it an ID, and assign any style properties we want to it – height, width, font family, etc.

Then we pass along the ID of that DIV when we instantiate the OpacityObject. We pass along the image path, too, and now we have a DIV with a translucent background. Cool!

Next we put some HTML text in the DIV and apply another unrelated object method to it (this object has nothing to do with the OpacityObject – it could be any code you have lying around). Now we can move the translucent DIV around the screen. Wheee! Floating Translucent DIV with HTML Text Inside.

So there's a glimpse of what's possible with the OpacityObject. You hardcore CSS/DOM folks, go nuts.

Variably Opaque-R-You

Download the source code for the object, functions, and examples we covered. All the code relies on our tweaked version of Browser Detect Lite, which is included as well. Variable Opacity Source Code.

One PNG and One PNG Only

This is all very exciting, but, as with many achievements that get web developers excited, making PNG work in today's browsers simply shouldn't be this hard. You might consider signing the petition to persuade Microsoft to provide full PNG support in Internet Explorer. With any luck, this article will soon be obsolete.

In the meantime, post any ideas for improvements to this code in the discussion forum for this article. The PNG home site, for instance, talks about a few other obscure browsers that should support alpha transparency, but that haven't been verified yet. If you can verify any of these claims, or have any other valuable input, let us know, and we'll update the code accordingly.

Resources

  • PNG Home Site
  • AlphaImageLoader Filter page on MSDN
  • PNG Behavior at WebFX, an alternate way to make PNGs display in IE. Involves using the runtimeStyle object. The downside with this approach is that it only correctly displays a PNG if it's displayed within an img> tag, not if it's a CSS background image
您可能感興趣的文章:
  • Opacity.js
  • CSS opacity - 實現圖片半透明效果的代碼
  • 純JS半透明Tip效果代碼
  • IE6下opacity與JQuery的奇妙結合
  • 原生js實現半透明遮罩層效果具體代碼
  • js+CSS實現彈出居中背景半透明div層的方法
  • js和jQuery設置Opacity半透明 兼容IE6

標簽:喀什 邯鄲 濱州 遼源 陽泉 南充 海東 東莞

巨人網絡通訊聲明:本文標題《Cross-Browser Variable Opacity with PNG》,本文關鍵詞  Cross-Browser,Variable,Opacity,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Cross-Browser Variable Opacity with PNG》相關的同類信息!
  • 本頁收集關于Cross-Browser Variable Opacity with PNG的相關信息資訊供網民參考!
  • 推薦文章
    婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av
    亚洲成国产人片在线观看| 爽好多水快深点欧美视频| 精品区一区二区| 日韩电影一二三区| 在线精品观看国产| 国产欧美精品国产国产专区| 极品尤物av久久免费看| 精品成人一区二区三区四区| 国产91在线观看| 国产欧美日本一区视频| 丰满白嫩尤物一区二区| 国产精品视频看| 老司机精品视频导航| 日韩一区二区影院| 国产精品一卡二| 亚洲欧洲三级电影| 欧美欧美欧美欧美| 奇米四色…亚洲| 日韩电影在线免费看| 日本美女一区二区| 精品亚洲aⅴ乱码一区二区三区| 欧美精品在线观看一区二区| 国产在线一区观看| 国产精品久久久久久久久免费相片| 色综合久久综合网欧美综合网| 亚洲午夜一区二区三区| 欧美成人女星排行榜| 国产精品一二三四区| 另类小说综合欧美亚洲| 亚洲国产精品高清| 亚洲一区二三区| 国产福利精品导航| 欧美日韩在线播放三区| 国产午夜精品福利| 亚洲一区二区欧美日韩| 国产白丝网站精品污在线入口| 91精品国产综合久久久久久久| 亚洲综合一区在线| 欧美精品一区二区三区久久久| 久久香蕉国产线看观看99| 亚洲视频1区2区| 麻豆久久一区二区| 国内精品写真在线观看| 一本色道**综合亚洲精品蜜桃冫| 欧美丰满少妇xxxbbb| 亚洲色欲色欲www在线观看| 美女性感视频久久| 欧美自拍偷拍一区| 欧美国产精品专区| 日韩高清不卡在线| 91精品1区2区| 亚洲视频资源在线| 国产成人精品亚洲午夜麻豆| 精品少妇一区二区三区在线播放| 一区二区欧美在线观看| 不卡视频免费播放| 国产精品嫩草99a| 国产一区二区在线免费观看| 精品乱人伦一区二区三区| 午夜视频在线观看一区| 在线成人av影院| 日韩中文字幕区一区有砖一区 | 欧美极品美女视频| 国产乱一区二区| 国产三级一区二区三区| 亚洲综合清纯丝袜自拍| 六月丁香综合在线视频| av午夜精品一区二区三区| 99视频精品全部免费在线| 国产三级一区二区| 亚洲精品在线观看网站| 久久狠狠亚洲综合| 国产日本亚洲高清| 欧美羞羞免费网站| 精品午夜久久福利影院| 亚洲天堂免费在线观看视频| 91精品蜜臀在线一区尤物| 成人性生交大片免费| 亚洲一区影音先锋| 欧美激情一区三区| 欧美日韩亚州综合| 国产aⅴ综合色| 日韩不卡一区二区| 亚洲精品网站在线观看| 337p日本欧洲亚洲大胆色噜噜| 色综合久久久久综合体桃花网| 精品一区二区在线观看| 亚洲国产色一区| 日本一区二区三区四区 | 亚洲韩国一区二区三区| 国产视频一区二区在线| 91精品国产一区二区三区蜜臀 | 91精品国模一区二区三区| www.av精品| 国产黄色精品网站| 久久电影网站中文字幕| 亚洲3atv精品一区二区三区| 亚洲欧美激情一区二区| 欧美国产一区二区在线观看| 精品电影一区二区| 欧美一区在线视频| 日本丶国产丶欧美色综合| 成人av在线观| 成人免费三级在线| 国产精品91xxx| 国产综合色精品一区二区三区| 青青青伊人色综合久久| 性欧美疯狂xxxxbbbb| 夜夜嗨av一区二区三区中文字幕 | 日韩亚洲欧美成人一区| 欧美日韩一区 二区 三区 久久精品| 97精品超碰一区二区三区| 成人av免费网站| 成人av网站在线观看免费| 成人一区二区视频| 大白屁股一区二区视频| 成人18视频日本| 91丝袜美腿高跟国产极品老师| av男人天堂一区| 91老师国产黑色丝袜在线| 日本韩国精品一区二区在线观看| 色一情一乱一乱一91av| 在线免费不卡视频| 欧美日韩和欧美的一区二区| 欧美高清hd18日本| 日韩欧美亚洲国产另类| 精品国产一区二区在线观看| 久久久蜜桃精品| 国产精品狼人久久影院观看方式| 国产精品高清亚洲| 亚洲成人午夜影院| 麻豆91精品91久久久的内涵| 国产伦精品一区二区三区免费迷 | 激情国产一区二区| 成人综合在线观看| 91日韩精品一区| 欧美日韩久久一区| 精品国内二区三区| 日韩毛片一二三区| 日本亚洲天堂网| 国产精品一区一区| 一本大道av伊人久久综合| 欧美另类高清zo欧美| 欧美成人福利视频| 亚洲人成精品久久久久久| 视频精品一区二区| 国产成人综合在线播放| 色婷婷av一区二区三区之一色屋| 538在线一区二区精品国产| 国产欧美精品一区二区三区四区| 亚洲麻豆国产自偷在线| 激情六月婷婷久久| 在线观看成人小视频| 久久在线免费观看| 亚洲电影你懂得| 国产成人在线色| 欧美一区二区三区公司| 亚洲欧洲日本在线| 久久99国产精品久久99| 色视频成人在线观看免| 久久一二三国产| 日韩精品五月天| 97国产精品videossex| 精品国产自在久精品国产| 亚洲一区日韩精品中文字幕| 国产999精品久久久久久绿帽| 欧美日韩国产高清一区二区三区 | 精品国产免费人成在线观看| 一区二区三区久久| 丁香六月久久综合狠狠色| 日韩三级中文字幕| 亚洲国产精品一区二区久久恐怖片| 国产又粗又猛又爽又黄91精品| 欧美亚洲另类激情小说| 中文字幕日韩欧美一区二区三区| 日韩av一区二| 欧美三级三级三级爽爽爽| 国产精品三级在线观看| 国产精品一区二区久久精品爱涩| 91精品视频网| 五月天一区二区| 欧美日韩亚洲综合在线| 一区二区三区色| 91美女在线看| 国产精品另类一区| 成人国产精品免费观看视频| 精品国产sm最大网站| 男女性色大片免费观看一区二区 | 91一区一区三区| 国产精品每日更新| 粉嫩高潮美女一区二区三区| 久久婷婷色综合| 国产综合久久久久影院| 日韩欧美激情四射| 日韩不卡一区二区三区| 日韩精品自拍偷拍| 国产一区二区三区四区五区入口| 欧美一区二区福利视频| 久久国产人妖系列| 精品成人私密视频|