久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

HTML5 Canvas 顏色選擇器

這段代碼是用HTML5來創建一個網頁顏色選擇器。首先在Canvas畫一幅圖,然后添加鼠標事件 “鼠標移動”,“鼠標點擊”。在鼠標移動的時候,顯示當前劃過的顏色預覽,在鼠標點擊的時
這段代碼是用HTML5來創建一個網頁顏色選擇器。首先在Canvas畫一幅圖,然后添加鼠標事件 “鼠標移動”,“鼠標點擊”。在鼠標移動的時候,顯示當前劃過的顏色預覽,在鼠標點擊的時候,選中當前顏色,顯示顏色的細節。

DEMO: http://www.oschina.net/uploads/demo/example158/ 

[代碼] [HTML]代碼

<!DOCTYPE html>
<html lang="en" >
    <head>
        <meta charset="utf-8" />
        <title><A title=HTML5 href="http://www.xyhtml5.com/">HTML5</A> canvas - Image color picker | Script Tutorials</title>
        <link href="<A title=css href="http://www.xyhtml5.com/css3">css</A>/main.<A title=css href="http://www.xyhtml5.com/css3">css</A>" rel="stylesheet" type="text/css" />
        <script type="text/<A title=javascript href="http://www.xyhtml5.com/javascript">javascript</A>" src="js/jquery-1.5.2.min.js"></script>
        <script type="text/<A title=javascript href="http://www.xyhtml5.com/javascript">javascript</A>" src="js/script.js"></script>
    </head>
    <body>
        <div class="container">
            <div class="column1">
                <canvas id="panel" width="500" height="333"></canvas>
            </div>
            <div class="column2">
                <div><input type="button" value="Next image" id="swImage" /></div>
                <div>Preview:</div>
                <div id="preview"></div>
                <div>Color:</div>
                <div>R: <input type="text" id="rVal" /></div>
                <div>G: <input type="text" id="gVal" /></div>
                <div>B: <input type="text" id="bVal" /></div>
                <div>RGB: <input type="text" id="rgbVal" /></div>
                <div>RGBA: <input type="text" id="rgbaVal" /></div>
                <div>HEX: <input type="text" id="hexVal" /></div>
                <hr />
            </div>
            <div style="clear:both;"></div>
        </div>
        <footer>
            <h2>HTML5 canvas - Image color picker</h2>
            <a href="http://www.script-tutorials.com/html5-canvas-image-color-picker/" class="stuts">Back to original tutorial on <span>Script Tutorials</span></a>
        </footer>
    </body>
</html>

[CSS]代碼

*{
    margin:0;
    padding:0;
}
  
body {
    background-color:#bababa;
    color:#fff;
    font:14px/1.3 Arial,sans-serif;
}
  
footer {
    background-color:#212121;
    bottom:0;
    box-shadow: 0 -1px 2px #111111;
    display:block;
    height:70px;
    left:0;
    position:fixed;
    width:100%;
    z-index:100;
}
  
footer h2{
    font-size:22px;
    font-weight:normal;
    left:50%;
    margin-left:-400px;
    padding:22px 0;
    position:absolute;
    width:540px;
}
  
footer a.stuts,a.stuts:visited{
    border:none;
    text-decoration:none;
    color:#fcfcfc;
    font-size:14px;
    left:50%;
    line-height:31px;
    margin:23px 0 0 110px;
    position:absolute;
    top:0;
}
  
footer .stuts span {
    font-size:22px;
    font-weight:bold;
    margin-left:5px;
}
  
.container {
    color:#000;
    margin:20px auto;
    position:relative;
    width:730px;
}
  
.column1 {
    float:left;
    width:500px;
}
  
.column2 {
    float:left;
    padding-left:20px;
    width:170px;
}
  
#panel {
    border:1px #000 solid;
    box-shadow:4px 6px 6px #444444;
    cursor:crosshair;
}
  
.column2 > div {
    margin-bottom:10px;
}
  
#swImage {
    border:1px #000 solid;
    box-shadow:2px 3px 3px #444444;
    cursor:pointer;
    height:25px;
    line-height:25px;
  
    border-radius:3px;
    -moz-border-radius:3px;
    -webkit-border-radius:3px;
}
  
#swImage:hover {
    margin-left:2px;
}
  
#preview {
    border:1px #000 solid;
    box-shadow:2px 3px 3px #444444;
    height:80px;
    width:80px;
  
    border-radius:3px;
    -moz-border-radius:3px;
    -webkit-border-radius:3px;
}
  
.column2 input[type=text] {
    float:right;
    width:110px;
}

[JavaScript]代碼

var canvas;
var ctx;
  
var images = [ // predefined array of used images
    'images/pic1.jpg',
    'images/pic2.jpg',
    'images/pic3.jpg',
    'images/pic4.jpg',
    'images/pic5.jpg',
    'images/pic6.jpg',
    'images/pic7.jpg',
    'images/pic8.jpg',
    'images/pic9.jpg',
    'images/pic10.jpg'
];
var iActiveImage = 0;
  
$(function(){
  
    // drawing active image
    var image = new Image();
    image.onload = function () {
        ctx.drawImage(image, 0, 0, image.width, image.height); // draw the image on the canvas
    }
    image.src = images[iActiveImage];
  
    // creating canvas object
    canvas = document.getElementById('panel');
    ctx = canvas.getContext('2d');
  
    $('#panel').mousemove(function(e) { // mouse move handler
        var canvasOffset = $(canvas).offset();
        var canvasX = Math.floor(e.pageX - canvasOffset.left);
        var canvasY = Math.floor(e.pageY - canvasOffset.top);
  
        var imageData = ctx.getImageData(canvasX, canvasY, 1, 1);
        var pixel = imageData.data;
  
        var pixelColor = "rgba("+pixel[0]+", "+pixel[1]+", "+pixel[2]+", "+pixel[3]+")";
        $('#preview').css('backgroundColor', pixelColor);
    });
  
    $('#panel').click(function(e) { // mouse click handler
        var canvasOffset = $(canvas).offset();
        var canvasX = Math.floor(e.pageX - canvasOffset.left);
        var canvasY = Math.floor(e.pageY - canvasOffset.top);
  
        var imageData = ctx.getImageData(canvasX, canvasY, 1, 1);
        var pixel = imageData.data;
  
        $('#rVal').val(pixel[0]);
        $('#gVal').val(pixel[1]);
        $('#bVal').val(pixel[2]);
  
        $('#rgbVal').val(pixel[0]+','+pixel[1]+','+pixel[2]);
        $('#rgbaVal').val(pixel[0]+','+pixel[1]+','+pixel[2]+','+pixel[3]);
        var dColor = pixel[2] + 256 * pixel[1] + 65536 * pixel[0];
        $('#hexVal').val( '#' + dColor.toString(16) );
    }); 
  
    $('#swImage').click(function(e) { // switching images
        iActiveImage++;
        if (iActiveImage >= 10) iActiveImage = 0;
        image.src = images[iActiveImage];
    });
});


本文由HTM5L中國網站小編整理轉發,轉載請注明出處。
【網站聲明】本站除付費源碼經過測試外,其他素材未做測試,不保證完整性,網站上部分源碼僅限學習交流,請勿用于商業用途。如損害你的權益請聯系客服QQ:2655101040 給予處理,謝謝支持。

相關文檔推薦

這篇文章主要介紹了有關HTML5頁面在iPhoneX適配問題,需要的朋友可以參考下
本篇文章主要介紹了html5中canvas圖表實現柱狀圖的示例,本文使用canvas來實現一個圖表,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
Adobe公司出品的多媒體處理軟件產品線較多,涵蓋了音視頻編輯、圖像處理、平面設計、影視后期等領域。這篇文章主要介紹了Adobe Html5 Extension開發初體驗圖文教程,非常不錯,需要的朋
這篇文章主要介紹了基于HTML5的WebGL經典3D虛擬機房漫游動畫,需要的朋友可以參考下
本篇文章主要介紹了canvas 實現 github404動態效果的示例代碼,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
這篇文章主要介紹了html5實現移動端適配完美寫法,需要的朋友可以參考下
主站蜘蛛池模板: 国产1区2区在线观看 | 亚洲精品久久久久久一区二区 | 国产美女在线精品免费 | 亚洲 欧美 另类 日韩 | 国产精品日本一区二区在线播放 | 精品视频免费在线 | 精品一区久久 | 亚洲国产成人久久综合一区,久久久国产99 | 操操操日日日 | 亚洲精品久久久蜜桃 | 国产成人精品一区二区三区视频 | 国产伦精品一区二区三毛 | 亚洲精品国产成人 | 亚洲情侣视频 | av中文字幕在线播放 | 精品日韩一区二区 | 亚洲免费av一区 | 91免费看片 | 国产精品一区三区 | 久久亚洲一区二区 | 国产精品久久久久久久模特 | 成人黄色电影免费 | 黑人一级黄色大片 | 亚洲精品久久久久久一区二区 | 亚洲成人免费观看 | 四虎最新视频 | 精品国产一区三区 | 日韩人体视频 | 精彩视频一区二区三区 | 国产精品免费一区二区三区四区 | 精品美女久久久 | 亚洲九九精品 | 成人视屏在线观看 | 99精品一区二区 | 欧美精品一区二区三区在线播放 | 91精品国产综合久久久久 | 亚洲精品短视频 | 91精品国产91久久久久久吃药 | 国产成人99久久亚洲综合精品 | 中文字幕日韩欧美一区二区三区 | 综合婷婷 |