英文:
Use an image as cursor with laravel project
问题
I would like to see an image as cursor if the pointer is inside a div.
This is my code:
FileController.php
public function addMarkClientFile(File $file)
{
$imagePath = asset('/img/mark-facsimile.png');
return view("documents.addMark", compact("imagePath"));
}
addMark.blade.php
@extends('layout.master')
@section('style')
@parent
<style>
.canvas-with-cursor {
cursor: url('{{ $imagePath }}'), crosshair !important;
}
</style>
@stop
@section('content')
....
<div class="canvas-with-cursor" id="pdf-preview"></div>
...
@stop
But I don't see the image but the 'crosshair' as fallback.
I also tried with an image get from an url on the web, and it works, so I think it is a problem with my url.
The image is located into /public/img/
folder.
If I debug it into the browser I get this "http://site.loc:9080/img/mark-facsimile.png" and trying to open the url, I can get the image without issue.
I also tried to change asset('/img/mark-facsimile.png')
with url('/img/mark-facsimile.png')
but it doesn't change.
英文:
I would like to see an image as cursor if the pointer is inside a div.
This is my code:
FileController.php
public function addMarkClientFile(File $file)
{
$imagePath = asset('/img/mark-facsimile.png');
return view("documents.addMark", compact("imagePath"));
}
addMark.blade.php
@extends('layout.master')
@section('style')
@parent
<style>
.canvas-with-cursor {
cursor: url('{{ $imagePath }}'), crosshair !important;
}
</style>
@stop
@section('content')
....
<div class="canvas-with-cursor" id="pdf-preview"></div>
...
@stop
But I don't see the image but the 'crosshair' as fallback.
I also tried with an image get from an url on the web, and it works, so I think it is a problem with my url.
The image is located into /public/img/
folder.
If I debug it into the browser I get this "http://site.loc:9080/img/mark-facsimile.png" and trying to open the url, I can get the image without issue.
I also tried to change asset('/img/mark-facsimile.png')
with url('/img/mark-facsimile.png')
but it doesn't change.
答案1
得分: 1
你的代码有效!我在我的Laravel应用程序上进行了测试,遇到了相同的问题,然后我减小了鼠标指针图像的尺寸,问题就解决了!
希望对你有帮助!
英文:
hey I think I found what the issues is:
> Icon size limits While the specification does not limit the cursor
> image size, user agents commonly restrict them to avoid potential
> misuse. For example, on Firefox and Chromium cursor images are
> restricted to 128x128 pixels by default, but it is recommended to
> limit the cursor image size to 32x32 pixels. Cursor changes using
> images that are larger than the user-agent maximum supported size will
> generally just be ignored.
Your code works! I have tested on my own Laravel application and had the same issue, then I reduced the dimensions of the cursor image and it worked fine!
Hope it helps!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论