使用图像作为 Laravel 项目的鼠标指针。

huangapple go评论116阅读模式
英文:

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(&#39;/img/mark-facsimile.png&#39;);
        return view(&quot;documents.addMark&quot;, compact(&quot;imagePath&quot;));
}

addMark.blade.php

@extends(&#39;layout.master&#39;)
@section(&#39;style&#39;)
    @parent
    &lt;style&gt;
        .canvas-with-cursor {
            cursor: url(&#39;{{ $imagePath }}&#39;), crosshair !important;
        }
    &lt;/style&gt;
@stop
@section(&#39;content&#39;)
....
&lt;div class=&quot;canvas-with-cursor&quot; id=&quot;pdf-preview&quot;&gt;&lt;/div&gt;
...
@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(&#39;/img/mark-facsimile.png&#39;) with url(&#39;/img/mark-facsimile.png&#39;) 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!

huangapple
  • 本文由 发表于 2023年3月31日 19:01:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75897784.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定