Changing the look of the cursor - html

I am making an online scratchcard and i need to know how to change my cursor into a coin.
here is an example of the code i already have tried:
<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>
and here is a part of the java script code
$.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.
};
I would really appriciate it if someone could help me out.

According to the github of the plugin there's a solution:
Update on the Fly
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');
So try this:
<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>

The syntax is
cursor:url(URL TO THE IMAGE)
I don't recommend disk paths (they might not even work). Use a relative path, i.e.
../Scratch the code/images/muntje.png

Try this:
cursor: url("images/muntje.png"), auto;
Make sure the path to the images directory is correct, relative to the path your CSS file is located.

Hi Please use the path like
cursor: url("/Bram/Bram/Scratch the code/images/muntje.png");
if u want to give the full path and access the html file locally
cursor: url("file://C:/xampp/htdocs/Bram/Scratch the code/images/muntje.png");

Put it in the CSS, not in the JavaScript. Maybe that works.
<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>

Related

How to drag and drop same element multiple times into another div box in JavaScript or jQuery?

I have two HTML div boxes. Let's say box A and box B. I want to drag and drop box A multiple times into box B. If I drop box A outside of box B then box A will revert back to it's original position. After I dropped the box A (clone) into box B I want to move box A (clone) into any position in box B. For now I did the codes to do that.
Now what I want is after I dropped box A into Box B, then if I drag and drop box A (clone) outside of box B, then box A (clone) need to hide or revert into it's original position (box A parent position).
HTML Codes
<div id="boxB"></div>
<br>
<div class="boxA">BOX A</div>
CSS Codes
#boxB {
width: 200px;
border: 5px solid black;
padding: 50px 50px;
margin: auto;
text-align: center;
background-color: #FFFFFF;
}
.boxA {
width: 40px;
border: 2px solid black;
text-align: center;
background-color: #F5D938;
cursor: pointer;
}
JavaScript + jQuery Codes
$(document).ready(function()
{
var x;
$(".boxA").draggable(
{
helper: "clone",
cursor: "move",
revert: true
});
$("#boxB").droppable(
{
accept: ".boxA",
drop: function(event, ui)
{
x = ui.helper.clone();
ui.helper.remove();
x.appendTo('#boxB');
$(x).draggable();
}
});
});
You can see demo : https://jsfiddle.net/zajjith/3kedjgb0/10/
If I drag and drop box A (clone) outside from box B then that clone box A need to revert back to it's original parent box A position or hide or delete.
I hope you understand what I want. Please check my codes and help me.
Refer to the Example at https://jqueryui.com/droppable/#revert
Using your code, you can do the following.
$(function() {
function getBounds(el) {
var p = $(el).position();
p.right = p.left + $(el).width();
p.bottom = p.top + $(el).height();
return p;
}
function isOver(a, b) {
var ap;
if (typeof a == "object") {
ap = a;
} else {
ap = getBounds(a);
}
var bp = getBounds(b);
return (ap.left > bp.left && ap.right < bp.right) && (ap.top > bp.top && ap.bottom < bp.bottom);
}
$(".boxA").draggable({
helper: "clone",
cursor: "move",
revert: "invalid"
});
$("#boxB").droppable({
accept: ".boxA",
drop: function(event, ui) {
var cl = ui.helper.clone();
cl.appendTo(this).draggable({
appendTo: "body",
stop: function(e, ui) {
if (isOver($.extend({}, ui.position, {
right: ui.position.left + ui.helper.width(),
bottom: ui.position.top + ui.helper.height()
}), $("#boxB")) == false) {
var a = getBounds($("body > .boxA"));
ui.helper.animate({
top: a.top,
left: a.left
}, function() {
ui.helper.remove();
});
} else {
console.log("Drop Inside");
}
}
});
ui.helper.remove();
}
});
});
#boxB {
width: 200px;
border: 5px solid black;
padding: 50px 50px;
margin: auto;
text-align: center;
background-color: #FFFFFF;
}
.boxA {
width: 50px;
border: 2px solid black;
text-align: center;
background-color: #F5D938;
cursor: pointer;
}
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div id="boxB"></div>
<br />
<div class="boxA">BOX A</div>

Shadow under fixed header upon scrolling

I am creating a website and I want shadow under my fixed header upon scrolling.
This means when the site loads there is no shadow under the header but when I scroll the page the shadow should appear below the header.
Here is my css code
EDIT : I am using reactjs for rendering the header
.nav-heading {
background-color: $white;
top: 0;
display: flex;
flex-direction: row;
position: fixed;
width: 100%;
z-index: 1;
// margin-top: 1.25rem;
}
.nav-heading::after {
position: fixed;
box-shadow: 0px 0px 6px 0px rgba(0, 0, 0, 0.7);
}
You could use JQuery, that is a javascript lib.
First you need to install JQuery.
One easy way is by CDN.
<script src="https://code.jquery.com/jquery-3.5.1.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>
Then add your script like this.
<script>
$(window).scroll(function(){
$(".nav-heading").css("box-shadow","here insert the value you want for the box-shadow")
})
</script>
If you want to the shadow fade out after scrolling you can use:
<script>
$(window).scroll(function(){
$(".nav-heading").css("box-shadow","here insert the value you want for the box-shadow").fadeOut( "slow" );
})
</script>
You can access more about in:
https://code.jquery.com/
Edit: How Using React.js
You can create functions to deal with the state of scrolled or not.
constructor() {
super();
this.state = {
className: 'notShadow'
}
}
handleScroll() {
if (document.documentElement.scrollTop > 430) {
this.setState({
className: 'withShadow'
})
}
}
componentDidMount() {
window.onscroll = () => this.handleScroll()
}
And then inside your header you can call the state as class.
<Nav className={this.state.className} />
If you don't know the number of pixels you can use:
console.log(document.documentElement.scrollTop);

babylon.js scene with transparent background won't show image/ text behind it z-index

i want to show text behind a babylon.js scene. I've made the background transparent but i can't see the text behind it. I've also tried z-index:-1 for the text.
I've only been learning Babylon since last night so I'm really not too sure whats going on. I'm also not good at java Script so any help would be greatly appreciated :)
\\\\\<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>BBY TIAL </title>
<script src="https://cdn.babylonjs.com/babylon.max.js"></script>
<style>
*{
background-color: pink;
}
#canvas {
width:80%;
height:80vh;
z-index:10;
border:0;
padding:0;
margin:0;
background-color: transparent;
}
#maya{
font-size: 300px;
color:white;
position: absolute;;
background-color: transparent;
z-index:-200;
}
#wright{
font-size: 300px;
color:white;
position: fixed;
z-index:1;
top:50vh;
left:40%;
background-color: transparent;
}
#full{
z-index: -9;
}
</style>
</head>
<body>
<h1 id="maya">MAYA</h1>
<h2 id="wright">WRIGHT</h2>
<canvas id="canvas"></canvas>
<script>
window.addEventListener('DOMContentLoaded', function(){
var canvas = document.getElementById('canvas');
var engine = new BABYLON.Engine(canvas, true,);
engine.enableOfflineSupport = false; // Dont require a manifest file
var createScene = function(){
var scene = new BABYLON.Scene(engine);
scene.clearColor = new BABYLON.Color4(0, 0, 0, 0);
var camera = new BABYLON.ArcRotateCamera("arcCam",
BABYLON.Tools.ToRadians(0),
BABYLON.Tools.ToRadians(0),
7.,BABYLON.Vector3.Zero(),scene);
camera.attachControl(canvas,true);
var light = new BABYLON.PointLight("PointLight",new BABYLON.Vector3(
5,5,5),scene);
light.parent = camera;
light.intensity = 1000.5;
BABYLON.SceneLoader.ImportMesh("","","ShippingContainer.babylon",
scene,function(newMeshes) {
newMeshes.forEach(function(mesh){
mesh.rotation = new BABYLON.Vector3(BABYLON.Tools.ToRadians(
0),0,0);
} );
});
return scene;
}
var scene = createScene();
engine.runRenderLoop(function(){
scene.render();
});
});
</script>
<h1 id="full">Maya<br/>Wright</h1>
<style>
#canvas{
background: transparent;
}
h1{
background-color: transparent;
font-size: large;
top:5vh;
left:40%;
position: absolute;
}
</style>
</body>
</html>
\\
The main issue here is setting background color to '*' elements, which prevents the image to be shown. When removing it (and adding it only to body), the h1s (with the negative z index) are shown behind the babylon scene:
Note that I didn't use your model, but the default babylon scene, as i have no access to it.
There is no need to set the canvas' background color to be transparent, the scene.clearColor parameter is doing it for you.

How to offset dataObject from referenceObject using popper.js?

How do I offset the boat from the anchor by a few pixels?
You can find a code pen where I have unsuccessfully tried to set an offset here
https://codepen.io/anon/pen/wXraLK?editors=1111
HTML
<script src="https://unpkg.com/popper.js/dist/umd/popper.min.js"></script>
<div class="anchor">Anchor</div>
<div class="boat">Boat</div>
CSS
.boat {
display: inline-block;
background-color: yellow;
}
.anchor {
display: inline-block;
background-color: gray;
}
JavaScript
var anchor = document.getElementsByClassName("anchor")[0];
var boat = document.getElementsByClassName("boat")[0];
var offsetTopModifier = function (data) {
data.offsets.popper.top += 50;
return data;
}
var popper = new Popper(
anchor,
boat,
{
placement: 'bottom-end',
modifiers: [offsetTopModifier]
}
);
This was the source that inspired my attempt:
https://github.com/FezVrasta/popper.js/issues/107
One work around was to set margins on the boat.

Is there a way to make a textbox auto expand without jQuery?

I have set resize to vertical but I would like that when the user fills the textbox then its size expands down. Is there any way this can be done without using an external library like jQuery?
Only in CSS and contentEditable="true" attribute.
div {
display:inline-block;
border: solid 1px #000;
min-height: 200px;
width: 300px;
}
Demo Here
This has been answered here already: Creating a textarea with auto-resize
<!DOCTYPE html>
<html>
<head>
<title>autoresizing textarea</title>
<style type="text/css">
textarea {
border: 0 none white;
overflow: hidden;
padding: 0;
outline: none;
background-color: #D0D0D0;
resize: none;
}
</style>
<script type="text/javascript">
var observe;
if (window.attachEvent) {
observe = function (element, event, handler) {
element.attachEvent('on'+event, handler);
};
}
else {
observe = function (element, event, handler) {
element.addEventListener(event, handler, false);
};
}
function init () {
var text = document.getElementById('text');
function resize () {
text.style.height = 'auto';
text.style.height = text.scrollHeight+'px';
}
/* 0-timeout to get the already changed text */
function delayedResize () {
window.setTimeout(resize, 0);
}
observe(text, 'change', resize);
observe(text, 'cut', delayedResize);
observe(text, 'paste', delayedResize);
observe(text, 'drop', delayedResize);
observe(text, 'keydown', delayedResize);
text.focus();
text.select();
resize();
}
</script>
</head>
<body onload="init();">
<textarea rows="1" style="height:1em;" id="text"></textarea>
</body>
</html>
Example: https://jsfiddle.net/hmelenok/WM6Gq/
Credits go to panzi, vote him up here: https://stackoverflow.com/a/5346855/1540350