2014-09-03 105 views
0

我正在製作在線刮刮卡,我需要知道如何將光標更改爲硬幣。更改光標的外觀

這裏是我已經嘗試了代碼示例:

<div id="krasvak" class="scratchpad"></div> 
    <style> 
    #krasvak { 
     width: 25%; 
     height: 100px; 
     border: solid 1px; 
     display: inline-block; 
    } 
    </style> 
    <script type="text/javascript" src="wScratchPad.js"></script> 
    <script type="text/javascript"> 

    $('#krasvak').wScratchPad({ 
     cursor: 'cursor: url("images/muntje.png"), auto;', 
     scratchMove: function (e, percent) { 
     console.log(percent); 
     if (percent > 70) 
     { 
      this.clear(); 
      window.alert("U heeft uw code gekrast"); 
      window.location.href='compleet.php'; 
     } 
     } 
    }); 
    $('#krasvak').wScratchPad('bg', 'images/slide1.png'); 
    $('#krasvak').wScratchPad('fg', 'images/overlay.png'); 
    $('#krasvak').wScratchPad('size', 10); 
    </script> 

這裏是java腳本代碼

$.fn.wScratchPad.defaults = { 
size  : 5,   // The size of the brush/scratch. 
bg   : '#cacaca', // Background (image path or hex color). 
fg   : '#6699ff', // Foreground (image path or hex color). 
realtime : true,  // Calculates percentage in realitime 
scratchDown : null,  // Set scratchDown callback. 
scratchUp : null,  // Set scratchUp callback. 
scratchMove : null,  // Set scratcMove callback. 
cursor  : 'crosshair' // Set cursor. 
}; 

我真的並欣賞它,如果有人可以幫助我的一部分出。

+0

[爲CSS自定義遊標使用外部圖像]可能的重複(http://stackoverflow.com/questions/18551277/using-external-images-for-css-custom-cursors) – WeSt 2014-09-03 14:24:07

+0

[Custom Cursor Image CSS ](http://stackoverflow.com/questions/336925/custom-cursor-image-css) – pjmorse 2014-09-03 14:27:52

回答

1

根據該插件的github有一個解決方案:在飛

var sp = $("#elem").wScratchPad(); 

sp.wScratchPad('size', 5); 
sp.wScratchPad('cursor', 'url("./cursors/coin.png") 5 5, default'); 

// Or directly with element. 

$("#elem").wScratchPad('image', './images/winner.png'); 


更新那麼試試這個:

<div id="krasvak" class="scratchpad"></div> 
    <style> 
    #krasvak { 
     width: 25%; 
     height: 100px; 
     border: solid 1px; 
     display: inline-block; 
    } 
    </style> 
    <script type="text/javascript" src="wScratchPad.js"></script> 
    <script type="text/javascript"> 

    $('#krasvak').wScratchPad({ 
     scratchMove: function (e, percent) { 
     console.log(percent); 
     if (percent > 70) 
     { 
      this.clear(); 
      window.alert("U heeft uw code gekrast"); 
      window.location.href='compleet.php'; 
     } 
     } 
    }); 
    $('#krasvak').wScratchPad('bg', 'images/slide1.png'); 
    $('#krasvak').wScratchPad('fg', 'images/overlay.png'); 
    $('#krasvak').wScratchPad('size', 10); 
    $('#krasvak').wScratchPad('cursor', 'url("./images/muntje.png") 5 5, default'); 
    </script> 
+0

非常感謝你的工作,真的appriciate :) – Bramos 2014-09-04 09:56:27

0

語法

光標:網址(URL到圖像)

我不建議磁盤路徑(他們可能甚至不工作)。使用相對路徑,即

../Scratch代碼/圖像/ muntje.png

+0

嘗試過,但仍然無法正常工作。無論如何感謝 – Bramos 2014-09-03 14:28:07

+0

@Bramos打開Web控制檯。你在那裏看到什麼錯誤? – BCartolo 2014-09-03 14:29:13

+0

我看不出錯誤。這就像瀏覽器甚至不知道代碼在那裏。 – Bramos 2014-09-03 14:32:13

0

試試這個:

cursor: url("images/muntje.png"), auto; 

製作到圖像目錄確保路徑是正確的,相對於您的CSS文件所在的路徑。

+0

嘗試過,但沒有奏效。無論如何感謝 – Bramos 2014-09-03 14:30:34

+0

你的目錄結構是什麼?如果你給目錄樹,我可以檢查什麼路徑是正確的。 – gidomanders 2014-09-03 14:41:18

+0

這是圖像的路徑C:\ xampp \ htdocs \ Bram \ Scratch the code \ images – Bramos 2014-09-03 14:49:13

0

如果u想給的完整路徑和訪問HTML文件在本地

cursor: url("file://C:/xampp/htdocs/Bram/Scratch the code/images/muntje.png"); 
0

把它放在CSS,而不是在JavaScript喜請使用路徑類似

cursor: url("/Bram/Bram/Scratch the code/images/muntje.png"); 

。也許這是有效的。

<div id="krasvak" class="scratchpad"></div> 
    <style> 
    #krasvak { 
     cursor: url("images/muntje.png"), auto; 
     width: 25%; 
     height: 100px; 
     border: solid 1px; 
     display: inline-block; 
    } 
    </style> 
    <script type="text/javascript" src="wScratchPad.js"></script> 
    <script type="text/javascript"> 

    $('#krasvak').wScratchPad({ 
     scratchMove: function (e, percent) { 
     console.log(percent); 
     if (percent > 70) 
     { 
      this.clear(); 
      window.alert("U heeft uw code gekrast"); 
      window.location.href='compleet.php'; 
     } 
     } 
    }); 
    $('#krasvak').wScratchPad('bg', 'images/slide1.png'); 
    $('#krasvak').wScratchPad('fg', 'images/overlay.png'); 
    $('#krasvak').wScratchPad('size', 10); 
    </script> 
+0

它沒有顯示站在java腳本文件中的「十字準線」,我會在問題中放置一部分java腳本,以便您可以查看它。 – Bramos 2014-09-04 09:32:38