Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
Apply CSS style to part of a canvas

I'd like to apply a specifc cursor png to only part of a canvas. I have this, which works fine for the whole canvas

.myClass {
    cursor: url('../img/myCursor.png') 7 33, auto; /* img hotspot centred*/
}

But I'd like, for example, to apply it to only the left hand 50% of canvas (or say first 300px on x axis).

Is this possible ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can position 2 divs over the canvas and have a different cursor property for each one:

const c = document.querySelector('canvas').getContext('2d');

c.beginPath();
c.moveTo(200, 0);
c.lineTo(200, 400);
c.stroke();

/* draw vertical line down middle */
.container {
  position: relative;
  width: 400px;
}

canvas {
  border: 1px solid;
}

.positioned {
  position: absolute;
  top: 0;
  height: 100%;
  width: 50%;
}

#left {
  left: 0;
  cursor: url('https://www.gravatar.com/avatar/0fdacb141bca7fa57c392b5f03872176?s=48&d=identicon&r=PG&f=1') 7 33, auto;
}

#right {
  cursor: url('https://www.gravatar.com/avatar/0fdacb141bca7fa57c392b5f03872176') 7 33, auto;
  right: 0px;
}
<div class="container">
  <canvas height="400" width="400"></canvas>
  <div class="positioned" id="left"></div>
  <div class="positioned" id="right"></div>
</div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!